Skip to content

2/5 refactor: assert TestGroup directly in algorithm tests#121

Open
vokracko wants to merge 2 commits intojerry-git:masterfrom
vokracko:refactor/test-assertions
Open

2/5 refactor: assert TestGroup directly in algorithm tests#121
vokracko wants to merge 2 commits intojerry-git:masterfrom
vokracko:refactor/test-assertions

Conversation

@vokracko
Copy link
Copy Markdown

@vokracko vokracko commented Apr 29, 2026

Second of five stacked PRs that fix #25. The end goal is to extend stable group membership (already true for least_duration since 0.8.0) to duration_based_chunks. This PR is preparation: it makes test assertions easier to evolve as later PRs change algorithm output.

Motivation. The downstream PRs change algorithm output ordering and add new fields to verify (durations, deselected lists). The existing per-attribute style would either need lots of new lines per assertion or would obscure mismatches when only one field is wrong. Consolidating to whole-TestGroup equality up-front means every later PR adds value to the same assertion shape.

What changes. Tests in tests/test_algorithms.py previously asserted each TestGroup field separately:

assert first.selected == [...]
assert first.deselected == [...]
assert first.duration == ...

After:

assert first == TestGroup(selected=[...], deselected=[...], duration=...)

Concrete values for every field, not just selected.

Stack.

The previous setup relied on pytest-cov (``--cov pytest_split
--cov tests`` in addopts) which has a long-standing limitation when
measuring a pytest plugin: the plugin imports happen during pytest's
plugin discovery, *before* pytest-cov starts tracing. Anything that
runs at import time (class bodies, decorators, type aliases, enum
definitions) is reported as uncovered even though it obviously
executed - the plugin wouldn't load otherwise. The
``CoverageWarning: Module pytest_split was previously imported, but
not measured`` made that explicit.

The cookiecutter template the project was generated from worked
around this by adding ``--cov tests`` to the addopts, inflating the
denominator with 100%-covered test files so the average reached 90%.
That pulled the number up but stopped reporting the actual source
coverage.

Switch to ``coverage run -m pytest`` followed by ``coverage report``.
Running ``coverage`` from the outside means tracing starts before
Python imports anything at all, so plugin import-time code is
counted. Real source coverage jumps from ~74% to 99%; threshold goes
from 90 to 95 to reflect that.
Tests previously asserted each TestGroup field separately
(`first.selected`, `first.deselected`, `first.duration`). Consolidate
to a single equality check against an expected TestGroup, with
concrete values for every field rather than only ``selected``.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Splits invalid when collection order not deterministic

1 participant