mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
ci: run the tests in parallel jobs and speed up the Sphinx build
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)
This commit is contained in:
committed by
Bobby Noelte
co-authored by
SchaafAlexander
Claude Opus 5.5
parent
e2726354c2
commit
57905b2024
+31
-1
@@ -133,8 +133,38 @@ def pytest_addoption(parser):
|
||||
)
|
||||
|
||||
|
||||
SERVER_MARKER = "eos_server"
|
||||
|
||||
|
||||
def mark_server_tests(items: Sequence[pytest.Item]) -> None:
|
||||
"""Mark the tests that start a real EOS or EOSdash server.
|
||||
|
||||
The servers listen on fixed ports, so these tests must not run next to each other. A test
|
||||
belongs to them if it uses the ``xprocess`` fixture, directly or through the server fixtures,
|
||||
or if it already carries the ``eos_server`` marker (a test that binds the ports without a
|
||||
fixture). Each of them gets the marker, which ``-m eos_server`` selects, and the same
|
||||
``xdist_group``, which keeps them on one worker under ``pytest -n ... --dist loadgroup``.
|
||||
|
||||
Args:
|
||||
items: The collected test items.
|
||||
"""
|
||||
for item in items:
|
||||
uses_server = "xprocess" in getattr(item, "fixturenames", ())
|
||||
if uses_server and item.get_closest_marker(SERVER_MARKER) is None:
|
||||
item.add_marker(SERVER_MARKER)
|
||||
if item.get_closest_marker(SERVER_MARKER) is not None:
|
||||
item.add_marker(pytest.mark.xdist_group(SERVER_MARKER))
|
||||
|
||||
|
||||
@pytest.hookimpl(tryfirst=True)
|
||||
def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
|
||||
"""Skip the browser tests unless --browser-test is given."""
|
||||
"""Mark the server tests, and skip the browser tests unless --browser-test is given.
|
||||
|
||||
Runs first: pytest-xdist reads the ``xdist_group`` marker in its own hook of this name. That
|
||||
plugin is registered after this file, so without ``tryfirst`` its hook runs before the marker
|
||||
is set here and the group has no effect.
|
||||
"""
|
||||
mark_server_tests(items)
|
||||
if config.getoption("--browser-test"):
|
||||
return
|
||||
skip_browser = pytest.mark.skip(reason="browser test: enable with --browser-test")
|
||||
|
||||
Reference in New Issue
Block a user