Skip to content

test: speed up pytest runs with xdist#230

Open
scotluns wants to merge 10 commits intomainfrom
codex-prepare-xdist-setup
Open

test: speed up pytest runs with xdist#230
scotluns wants to merge 10 commits intomainfrom
codex-prepare-xdist-setup

Conversation

@scotluns
Copy link
Copy Markdown
Contributor

@scotluns scotluns commented Apr 24, 2026

Why

This reduces test runtime by letting pytest run safely in parallel. The STIX cache change is mostly there to make xdist practical: it avoids each worker doing the same setup work and keeps the parallel run from fighting over shared test data.

What changed

  • Added pytest-xdist and switched CI to run pytest with two workers.
  • Changed the ATT&CK STIX test fixture from an autouse session fixture to an explicit shared fixture, so tests only prepare STIX data when they need it.
  • Store downloaded STIX bundles in .pytest_cache/attack-stix instead of a per-run temp directory.
  • Warm the shared STIX cache before xdist workers start. Workers read from that cache instead of downloading or preparing bundles independently.
  • Kept the STIX pytest options under tests/conftest.py, so --stix-enterprise, --stix-mobile, --stix-ics, --attack-version, and --stix-version still work with the xdist cache path.
  • Removed the root-level conftest.py added on main; pytest setup now stays under tests/.
  • Added just recipes and contributor guidance for parallel tests and STIX-backed test data.
  • Added PyPI as the explicit uv index so lock generation is stable.

How to verify

  • uv lock --check
  • uv run ruff format --check tests/conftest.py tests/changelog/conftest.py
  • uv run ruff check tests/conftest.py tests/changelog/conftest.py
  • uv run --extra dev pytest --help
  • uv run --extra dev pytest -n 2 --attack-version 19.0 tests/test_to_excel.py::test_enterprise_latest -q
  • uv run --extra dev pytest -n 2 -q

Known gaps

No known follow-up work from local validation.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant