Skip to content

bug: an installed pytest-randomly silently randomizes local runs, surfacing latent order dependencies as phantom regressions #2891

Closed

Description

@vybe

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:

  1. 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.
  2. 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-randomly active either fails fast with an explanatory message or prints an unmissable banner naming the seed and how to disable it
  • tests/run-full.sh and tests/run-core.sh pin 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

  1. added
    priority-p2
    type-bug
    theme-devex
    complexity-medium
    status-ready
    on Sep 18, 2026
  2. removed
    status-ready
    on Sep 18, 2026
  3. dolho commented on Sep 18, 2026

    @dolho
    Contributor

    /claim

  4. added
    status-in-progress
    on Sep 18, 2026
  5. github-actions commented on Sep 18, 2026

    @github-actions

    Claimed by @dolho. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/2891-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #2891
  6. added 2 commits that reference this issue on Oct 20, 2026
  7. added
    status-in-dev
    and removed
    status-in-progress
    on Oct 23, 2026
  8. removed
    status-in-dev
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-mediumpriority-p2theme-devextype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions