Repository navigation
Description
Summary
pytest-randomly is deliberately kept out of tests/requirements-test.txt (installed in-workflow only) precisely because "pytest auto-discovers installed plugins and it would silently randomize every local run". Nothing enforces that. When the plugin ends up in a local test virtualenv anyway, every local run-full.sh / run-core.sh invocation is randomized with no signal, and pre-existing latent order dependencies surface as what look like product regressions.
Context
Observed on a test virtualenv with pytest-randomly 4.1.0 installed. A full run produced 19 failures and 12 errors. Every unit-tier one passes in isolation:
| Test file | Under randomization | With -p no:randomly |
|---|---|---|
tests/unit/test_1081_physical_meter.py |
2 failed (clamp assertions, assert 5 == 2 / assert 3 == 2) |
2 passed |
tests/unit/test_2638_subscription_switch_on_turn.py |
3 failed | 54 passed |
tests/unit/test_subscription_auto_switch_pingpong.py |
12 errors (importlib.reload -> module ... not in sys.modules) |
30 passed |
Four api-tier failures (test_shared_folders.py::test_folders_default_values, test_nevermined_payments.py::test_info_no_config, test_nevermined_permissions.py::test_get_config_no_config, and probably test_subscriptions.py::test_round_robin_distribution) are diagnosed as the same class by source inspection — a module-scoped created_agent fixture shared across tests where some mutate state that others assert is pristine — but were not isolated individually, so that half should be confirmed during the fix.
The documented rationale for the exclusion exists in two places (tests/requirements-test.txt:18-22 and .github/workflows/backend-unit-test.yml:156-162) but is unenforced, so it holds only as long as nobody's environment drifts.
Two distinct problems are worth separating:
- No signal. A randomized local run should announce itself unmissably, or refuse to run unless explicitly opted in. As-is, the only symptom is failures that don't reproduce.
- Real order dependencies. The fixture-sharing flakes above are genuine latent defects regardless of how they were surfaced — randomization revealed them, it did not cause them.
Cost of the current state: each of these was triaged as a suspected logic regression before isolation showed otherwise.
Acceptance Criteria
- A local run with
pytest-randomlyactive either fails fast with an explanatory message or prints an unmissable banner naming the seed and how to disable it -
tests/run-full.shandtests/run-core.shpin deterministic ordering explicitly rather than depending on the plugin's absence - The three unit-tier order dependencies above are fixed at the source (not quarantined), or explicitly marked with a stated reason
- The four suspected
api-tier order dependencies are confirmed by isolation and fixed — state-asserting tests must not share a mutated module-scoped fixture - Whether CI's three-seed unit run already hits these is answered explicitly in the fix
Technical Notes
tests/conftest.py can detect the active plugin via config.pluginmanager.hasplugin("randomly") and act on it in one place.
CI already runs the unit tier under three seeds (.github/workflows/backend-unit-test.yml). Either those seeds do not hit these orderings, or the failures are being tolerated — worth confirming, because if CI is green on the same code that fails locally under a different seed, three seeds is not enough coverage to claim order-independence.
Activity
dolho commentedon Sep 18, 2026
/claim
github-actions commentedon Sep 18, 2026
Claimed by @dolho. Label
status-in-progressadded.Next steps:
feature/2891-<short-slug>Fixes #2891style(tests): drop the trailing blank line in unit/conftest.py (#2891)
Merge pull request #3841 from Abilityai/fix/2891-randomly-guard
fix(tests): refuse a silently shuffled local run, announce an opted-i…