Skip to content

Order-dependent fixture-loss: tests/host/test_company_attribution.py loses tests/host/conftest.py fixtures when collected after tests/test_migration_deploy_safety.py #374

Closed

Description

@Senkichi

What

Running tests/test_migration_deploy_safety.py in the same pytest invocation as tests/host/test_company_attribution.py, with test_migration_deploy_safety.py collected FIRST, makes every db_conn-requesting test in test_company_attribution.py fail at fixture setup:

E       fixture 'db_conn' not found
>       available fixtures: anyio_backend, anyio_backend_name, ..., worker_id

The listed "available fixtures" contains none of tests/host/conftest.py's fixtures at all (no db_conn, no postgres_test_dsn, not even the autouse _reset_analytics_pseudonym_salt/_pool_watchdog_disabled_by_default) -- tests/host/conftest.py appears not to have been loaded for this module in that run.

Minimal reproduction

uv run pytest tests/host/test_m0006_analytics_consent_version.py tests/test_migration_deploy_safety.py tests/host/test_company_attribution.py -n0
# -> 120 passed, 4 errors (all 4 in test_company_attribution.py)

Order-dependent: swapping so test_company_attribution.py is collected first makes all 3 files pass clean:

uv run pytest tests/host/test_company_attribution.py tests/host/test_m0006_analytics_consent_version.py tests/test_migration_deploy_safety.py -n0
# -> 124 passed

test_company_attribution.py also passes standalone, and passes paired with test_migration_deploy_safety.py alone (no third file) -- the failure needs test_migration_deploy_safety.py PLUS at least one tests/host/ file PLUS test_company_attribution.py together, in that collection order.

Why I found this

Investigating locally with POSTGRES_ADMIN_DSN set while adding tests/host/test_m0028_careers_crawl_flag_reason.py (#370's fix): a targeted batch run (test_m0028...py + test_m0006/8/9/10/12...py + test_migrate.py + test_migration_deploy_safety.py + test_boundary.py + test_company_attribution.py) produced 176 passed / 4 errors, all 4 in test_company_attribution.py. Confirmed via bisection this reproduces identically with my new file removed from the batch entirely -- it is pre-existing, not caused by that PR's diff, so I'm not fixing it inline there (out of that PR's scope) and filing it here instead.

Likely mechanism (untested hypothesis)

test_migration_deploy_safety.py sits directly under tests/ (no tests/__init__.py, no tests/conftest.py), so pytest's rootless import mode imports it as a bare top-level module and inserts tests/ onto sys.path. tests/host/ DOES have __init__.py, so tests/host/conftest.py is imported qualified as tests.host.conftest. test_migration_deploy_safety.py's own module-level work (_all_migration_modules() calls importlib.import_module for every jobcannon.db.migrations.m* submodule at collection/test-run time) is the most likely candidate for whatever side effect desyncs conftest fixture registration for a directory collected afterward, but this needs an actual pytest-internals investigation, not a guess -- filing the observed behavior + minimal repro rather than a diagnosis.

Impact

  • CI's default full-suite run (-n auto --dist loadgroup, pytest tests/) does not appear to hit this today (repo CI is green), so it's likely specific to targeted, hand-picked subset invocations across tests/ and tests/host/ together -- exactly the pattern CLAUDE.md's testing-budget guidance recommends agents use before pushing. An agent trusting a false-negative fixture error here could misdiagnose a real regression, or waste time chasing a phantom failure.
  • Unverified whether xdist (-n auto) is also affected, or only serial (-n0) collection order.

Suggested next step

Someone (or an agent) with time to spend on pytest-internals should trace _pytest.fixtures' conftest-chain resolution for tests/host/test_company_attribution.py's node across both collection orders, ideally with pytest --fixtures-per-test / -p no:cacheprovider --collect-only -v diffed between the two orders, to confirm or refute the import-mode hypothesis above.

Activity

  1. added
    automated-readyIssue is ready for deterministic agentic automation.
    agent:in-progressA worker is implementing this issue.
    agent:pr-openA worker PR exists for this issue.
    agent:reviewingThe orchestrator is adversarially reviewing the worker PR.
    and removed
    agent:in-progressA worker is implementing this issue.
    agent:reviewingThe orchestrator is adversarially reviewing the worker PR.
    on Sep 22, 2026
  2. added
    agent:doneAutomation completed and the issue was merged or resolved.
    and removed
    agent:pr-openA worker PR exists for this issue.
    automated-readyIssue is ready for deterministic agentic automation.
    on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:doneAutomation completed and the issue was merged or resolved.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions