Skip to content

Root-level test_*.py scripts call sys.exit() at import, corrupting pytest collection #11

@bradsmithmba

Description

@bradsmithmba

Summary

Four root-level files (test_api.py, test_e2e.py, test_installed_api.py, test_options_simple.py) are standalone scripts that call sys.exit() at module scope. pytest discovers them as test files and imports them, which kills the test runner process mid-collection.

Files

test_api.py
test_e2e.py
test_installed_api.py
test_options_simple.py

All four follow the same pattern:

if __name__ == "__main__":
    # ...
    sys.exit(0 if result else 1)

However, some also call sys.exit() at import time (not guarded by __name__ == "__main__"), or pytest imports them and the script body runs. Either way, the result is INTERNALERROR> SystemExit during collection.

Impact

  • Running pytest from the repo root causes INTERNALERROR: SystemExit before any tests execute
  • The failure is silent: no test count, no failure list, just an internal crash
  • CI pipelines using pytest . or pytest without a scope argument will always fail

Recommended fix

Option A: Move these files out of pytest's discovery path. Create a scripts/ directory and relocate them there. Add scripts/ to testpaths in pytest.ini exclusions or add a conftest.py collect_ignore list.

Option B: Convert them to proper pytest test modules under tests/ with proper test functions, removing all sys.exit() calls and if __name__ == "__main__" blocks.

Option C: Add to pytest.ini:

[pytest]
collect_ignore = ["test_api.py", "test_e2e.py", "test_installed_api.py", "test_options_simple.py"]

Option B is the cleanest long-term fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions