mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 23:16:18 +01:00
The single test job ran all tests one after the other on one runner,
including the Sphinx build and the Docker checks (11-19 min). It is now
split so that every test still runs exactly once:
- docs-test, docker-test: the Sphinx build (new marker "docs") and the
Docker / Home Assistant add-on checks ("docker") in jobs of their own.
- test-server: the tests that start EOS or EOSdash on the fixed ports.
The collection hook marks every test that uses the xprocess fixture
with "eos_server" and puts them into one xdist group, so
"pytest -n auto --dist loadgroup" also works locally. A test that
binds the ports without a fixture carries the marker itself.
- test-shard: all other tests in four shards of about equal runtime
(scripts/shard_test_files.py, runtimes in scripts/test_durations.json),
each with pytest-xdist.
- test-count: fails if these parts do not add up to the tests of one
plain run.
- test: keeps the name of the required check. It prints the combined
coverage report and fails if any of the jobs above failed.
COVERAGE_CORE=sysmon measures line coverage through sys.monitoring:
the report is the same, the test time drops by about a third. The
combined report misses 1-3 statements more than a single run, in lines
that only run when a test finds state left by an earlier test.
The Sphinx build spent 74 % of its time in one search of
PythonDomain.find_obj (sphinx-doc/sphinx#11282). The local extension
docs/_ext/pyxrefindex.py answers it from an index of name endings with
the same matches in the same order; a build has a byte-identical
objects.inv. It copies the logic of Sphinx 9.0.4 and is only active for
that version; TestPyXrefIndex compares it with the installed Sphinx and
fails after a Sphinx update until the version is raised. The
documentation test builds with -j (up to four jobs); its pages can
differ from a serial build in the target of ambiguous cross-references.
Read the Docs builds without -j. Sphinx build on GitHub runners:
427-480 s -> 180-233 s.
make test-ci runs the commands of these jobs one after the other.
On GitHub runners the tests are done after about 2 minutes; the
required check ends with docs-test after about 4-5 minutes.
Additional changes
Add pytest-xdist to the development dependencies
List the 25 slowest tests in each test job (--durations=25)
Test version() directly; it was covered only through the Sphinx test
Add a "Keep Tests Fast" tip, the server marker rule, the extension and
test-ci to the development guide and the testing skill
Refs #1553
Co-authored-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-fable-5-2)
40 lines
1.7 KiB
Markdown
40 lines
1.7 KiB
Markdown
---
|
|
name: testing
|
|
description: Use when adding or updating pytest tests, fixing bugs, or changing behavior that needs test coverage.
|
|
---
|
|
|
|
# Testing
|
|
|
|
## When to use
|
|
|
|
- Any behavior change or bug fix.
|
|
|
|
## Rules
|
|
|
|
- **Prefer adding tests to existing test classes in existing test modules.**
|
|
Extend the relevant class/module rather than creating new files.
|
|
- Create a new test module only when:
|
|
- functionality is a distinct aspect that does not fit any existing module, or
|
|
- it targets a different component/test target.
|
|
- Follow existing conventions, fixtures, and markers.
|
|
- Prefer deterministic, isolated tests; mock external services/devices.
|
|
- Cover boundary conditions and error paths.
|
|
- Do not weaken tests to accommodate implementation defects.
|
|
- Keep each test case well under a second. No real-time sleeps or wait loops
|
|
(use synthetic timestamps), no full cartesian `parametrize` over independent
|
|
axes, and extend an existing parametrized test before writing a new one.
|
|
The CI log lists the 25 slowest tests (`--durations=25`).
|
|
- A test that starts an EOS or EOSdash server on the fixed ports uses the server
|
|
fixtures (`server_setup_for_class`, `server_setup_for_function`), which mark it
|
|
`eos_server` through the `xprocess` fixture. If a test must bind these ports
|
|
without them, mark it `@pytest.mark.eos_server` itself: CI runs these tests in
|
|
their own job, all others in parallel.
|
|
|
|
## Verify
|
|
|
|
- Run the relevant pytest tests and checks with the project's configured
|
|
commands and environment before declaring the change complete.
|
|
- Run a full test run:
|
|
- Only one run at a time. Stop any running full test run before start of a new.
|
|
- Run the equivalent of make gen-docs before a full run.
|