Skip to content

fix(tests): test_audit_log_unit.py — 50 collection ImportErrors when run in full suite #762

Closed

Description

@AndriiPasternak31

Summary

50 tests in tests/test_audit_log_unit.py fail with ImportError at collection time when run as part of the full integration suite (pytest tests/). All 50 tests pass when run in isolation (pytest tests/test_audit_log_unit.py).

This is the largest single source of collection-error noise in the integration suite — 50 of the 65 collection errors observed on 2026-05-09 — and it masks signal for any other regression.

Context

Discovered via full test suite run on 2026-05-09:

26 failed, 1891 passed, 170 skipped, 300 warnings, 65 errors in 2508.21s (0:41:48)

Of those 65 errors, 50 are this file. Re-running in isolation:

pytest tests/test_audit_log_unit.py
# 50 passed

The file already stubs utils.helpers defensively at module top, then monkeypatches db.connection, db.audit, services.platform_audit_service, database, models per-test. The symptom suggests a different file, run earlier in the suite, leaves something in sys.modules (likely one of those modules) that breaks one of these imports at the next collection.

Reproduction

cd tests && source .venv/bin/activate
pytest --ignore=unit --ignore=process_engine --collect-only 2>&1 | grep "test_audit_log_unit"

Acceptance Criteria

  • pytest tests/ reports 0 collection errors against tests/test_audit_log_unit.py.
  • All 50 tests still pass when the file runs (a) standalone, (b) in the full integration suite.
  • Root-cause polluter identified in the PR description (which earlier file mutates sys.modules).

Investigation hints

  • Bisect by running pytest tests/test_<earlier>.py tests/test_audit_log_unit.py over alphabetically-earlier files until the breakage reproduces.
  • Likely candidates: any file collected before test_audit_log_unit.py that touches services.platform_audit_service, db.audit, or database.
  • Workaround until root cause: extend the conftest defensive-snapshot pattern that fix(tests): green the unit-test suite (closes #660) #714 used for tests/unit/test_file_upload.py (snapshot the real db.* and services.platform_audit_service modules before the polluter, restore on teardown).

Related

Activity

  1. added a commit that references this issue on May 11, 2026
    3043631
  2. added
    status-in-dev
    on May 11, 2026
  3. 74 remaining items

  4. added a commit that references this issue on Aug 16, 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

    priority-p2type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions