Repository navigation
test(cli): no test module reads a path from its own file or imports a test module, checked in the full gate - #1711
Merged
Conversation
… test module, checked in the full gate The last eight Path(__file__) lines, in six test modules, read tests.support.paths, and no module keeps a root constant of its own or an alias of one. Four modules drop theirs and import REPO_ROOT, tests/test_roadmap_config.py imports it in place of its inline root, and tests/test_roadmap_github_store.py imports FIXTURES and names its own directory ROADMAP_FIXTURES. tests/test_test_module_independence.py parses every Python file under tests/ but tests/fixtures/ once, conftests and helper modules included, and names, as path:line, each bare __file__ outside tests/support/ and each import of a test module or a conftest. pytest's own python_files patterns say what a test module is, a relative import is resolved against the importing module's package and one past the top-level package is reported, and from X import n is checked as X and, when X is a package or X/n.py exists, as X.n. So a module's __file__ attribute, imports of devops-cli modules named test_* and a function imported from a plain support module pass. A seeded tree under tmp_path pins each reported and each allowed form, and spells the banned forms in parts, so a text search over tests/ finds none of them. The ban runs only in the full gate, as the owner decided on the issue: parsing the 526 Python files under tests/ takes about 1 s idle and the ban 1.8 s. It lives in a module of its own that imports nothing from devops-cli and nothing under tests/, spells no devops-cli module's dotted name and is named for none, so the selector maps no change to it; the plan's place, tests/test_architectural_invariants.py, is selected by 31 source modules. Two tests in tests/test_test_selection.py hold this. In a repository whose src/ is this one's and whose tests/ holds the ban beside the suite's helper modules and conftest, no selection short of the whole suite reaches it, over every source module, over the helper modules that do not reach the whole suite, or over any conftest, which may narrow to its directory. And the full gate collects it: the test step's pytest arguments and pyproject.toml's addopts each equal an exact list, testpaths and python_files their exact values, and no conftest or support module binds collect_ignore, collect_ignore_glob or pytest_ignore_collect, so any path, ignore, deselect, keyword or marker filter added fails the test. A move proof in a scratch worktree moved tests/test_release.py, tests/test_roadmap_dry_runs.py and tests/test_security_kubelinter.py into package directories with git mv: with no other edit the suite passed and collected the same IDs once each ID's directory was dropped. docs/TESTING.md describes the check as existing, changelog.d/1312.md is the item's one fragment, for its five pull requests, and the task file records this pull request, PR 2's outcome against its own parent, and every criterion of the plan. Closes #1312
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The last of #1312's five pull requests. No test module reads a path from its own file or imports another test module, and a ban that runs in the full gate keeps it that way. This closes #1312.
The last sites.
Path(__file__)lines, in six test modules, readtests.support.paths.tests/test_github_session.pyusesREPO_ROOT.tests/test_roadmap_github_store.pyimportsFIXTURESand names its own directoryROADMAP_FIXTURES.The ban:
tests/test_test_module_independence.py.tests/once, excepttests/fixtures/, conftests and helper modules included.path:line:__file__outsidetests/support/;import,from X import nandasaliases;python_filespatterns say what a test module is. A relative import resolves against the importing module's package.from X import ncounts asX.nonly whenXis a package orX/n.pyexists.__file__attribute, devops-cli modules namedtest_*, and functions imported from a plain support module.tmp_pathpins each reported and each allowed form, including plants in a conftest and a helper. The banned forms are spelled in parts, so a text search overtests/finds none.Full gate only (the owner's decision on #1312).
tests/and spells no devops-cli module's name, so the selector maps no change to it. The plan's location,tests/test_architectural_invariants.py, is selected by 31 source modules.tests/test_test_selection.pyhold this:src/is this one's.addoptseach equal an exact list, andtestpathsandpython_filestheir exact values. No conftest or support module bindscollect_ignore,collect_ignore_globorpytest_ignore_collect. So any path, ignore, deselect, keyword or marker filter added to the gate fails it.Move proof. In a scratch worktree, three modules were
git mv'd into package directories:tests/test_release.py,tests/test_roadmap_dry_runs.pyandtests/test_security_kubelinter.py. With no other edit, the suite passed and collected the same IDs once each ID's directory part was dropped.Records.
docs/TESTING.mddescribes the check as existing.changelog.d/1312.mdis the item's one fragment, for its five pull requests.devops ci test tests/support/paths.py --no-fallbackexits 1" is recorded as superseded by PR 3's precise rule, with its reason.rg -n 'tests\.conftest' testsprints one line, a subprocess source string intests/test_openblas_worker_threads.py(test(cli): tests wait for a background thread with one generous bound, not a 1-second deadline, so they pass under load #1664), which the ban rightly ignores.Verification
X.ncheck;X.nalways;tests/support/exemption;tests/fixtures/exclusion;test_prefix only;Path(...)only;test_architectural_invariants.py, into a directory beside a fixtures-only conftest, importingtests.support.paths, or withdevops_cliin its docstring.--deselect,--ignoreor-kin the gate,--ignoreinaddopts, andcollect_ignorein a conftest.X.nrule, the relative-import report, and PR 2's outcome record.uv run devops cipassed (pre-push hook).Closes #1312
Fail-to-pass: not applicable: changes only the test harness