Skip to content

pytest.ini is dead config that silently shadows pyproject.toml (--strict-markers, testpaths, markers all inert) #130

Description

@jeremymanning

Part of #108 · Phase 1 · Discovered while red-teaming #109.

Problem

pytest.ini uses the section header [tool:pytest]. That header is only valid in setup.cfg. In a file named pytest.ini, pytest requires [pytest].

pytest still selects the file as its config — and having selected it, stops looking, so pyproject.toml's [tool.pytest.ini_options] is never read.

Verified:

$ pytest tests/unit/test_billable_safety.py --co
rootdir: /Users/jmanning/clustrix
configfile: pytest.ini              <- not pyproject.toml

$ pytest --markers | grep -cE "^@pytest.mark.(expensive|real_world|dartmouth_network)"
0                                   <- no project markers registered at all

$ pytest <file with @pytest.mark.definitely_not_registered_xyz> --co -q
1 test collected                    <- --strict-markers is NOT active

Everything currently inert

Both files declare these; neither takes effect:

Setting Intended Actual
addopts (-v --tb=short --strict-markers, and -n 4 --dist loadfile in pyproject) applied to every run ignored
testpaths limit collection to tests ignored — bare pytest collects the whole repo
markers (13 of them) registered none registered
filterwarnings suppress paramiko/crypto noise ignored
--strict-markers typo in a marker = error inert

Why this matters beyond tidiness

  1. It invalidates a premise of several other issues. pip install -e ".[dev]" produces an environment where pytest cannot start #110 reports that pip install -e ".[dev]" cannot start pytest because addopts requires xdist. That is true only on branches where pytest.ini is absent — the epic branch deleted it. On master, addopts never applies. Any statement about "the addopts" needs to say which config was live.
  2. Marker-based safety is illusory. tests/integration/ is unmarked, so the documented unit-test command provisions billable AWS EKS clusters #109's gate deliberately does not rely on markers, which turns out to have been necessary: applying pytest.mark.expensive today produces PytestUnknownMarkWarning, not a usable selector.
  3. --strict-markers being inert hides typos. scripts/test_discovery.py (on the closed epic branch) found 1,532 marker-hygiene issues that a live --strict-markers would have caught at source.

Fix — needs care, do not just flip it

The obvious change ([tool:pytest][pytest], or delete pytest.ini so pyproject wins) will activate --strict-markers, testpaths, and possibly -n 4. Any test using an unregistered mark then becomes a hard error, and there are 1,532 known marker issues. Sequence it:

  • Decide on ONE config source. Recommendation: delete pytest.ini, keep pyproject.toml (it has the fuller marker list — 13 vs 10 — and is the modern convention).
  • Before activating, inventory every mark actually used: grep -rhoE "@pytest\.mark\.[a-z_]+" tests/ | sort -u and reconcile against the registered list.
  • Confirm pytest-xdist is installed wherever addopts will now apply (ties to pip install -e ".[dev]" produces an environment where pytest cannot start #110).
  • Verify testpaths activation does not pull tests/real_world/ into default runs.
  • Land --strict-markers last, once the marker inventory is clean.
  • Add a test asserting Config.inifile is the expected file, so a future stray config file cannot silently shadow it again.

Verification

pytest --co -q tests/unit/ 2>&1 | grep -i configfile
pytest --markers | grep -cE "^@pytest.mark."

Activity

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

    P1-highRequired for production readinessbugtestingTest suite, CI, coverage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions