Repository navigation
Description
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 acrosstests/andtests/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
fix(db): add companies.careers_crawl_flag_reason column (#375)
fix(db): clear careers_crawl_flag_reason on careers_url attribution w…