Repository navigation
fix: resolve coverage config relative to pytest's rootdir (#692) - #765
Open
DawnofGenX wants to merge 1 commit into
Open
DawnofGenX wants to merge 1 commit into
DawnofGenX wants to merge 1 commit into
Conversation
…#692) Coverage resolves a relative `config_file` (the default `.coveragerc`, and the `pyproject.toml` / `setup.cfg` / `tox.ini` fallbacks) and a relative `data_file` against the current working directory. Running pytest from a subdirectory therefore silently ignored the project's coverage configuration (e.g. `[tool.coverage.report] exclude_also`), and wrote `.coverage` into the subdirectory instead of the project root. Pass pytest's rootdir to the controllers and use it as the anchor when no explicit `--cov-config` was given; it only differs from the cwd in exactly that case.
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.
Problem
Coverage resolves a relative
config_file(the default.coveragerc, plus thepyproject.toml/setup.cfg/tox.inifallbacks) and a relativedata_fileagainst the current working directory. Running pytest from a subdirectory
therefore silently ignores the project's coverage configuration:
cd project && pytest tests/→exclude_alsoapplies (100%).cd project/tests && pytest .→exclude_alsois ignored, and.coverageis written into
tests/rather than the project root.Changes
Pass pytest's rootdir through to the controllers and use it as the anchor for
coverage's config/data lookup. It only differs from the cwd in exactly the case
that is broken (running from a subdirectory), so root-level invocations are
unaffected. An explicit
--cov-configstill wins.Verification
test_config_at_rootdir_used_from_subdirectoryfails onmain(the excluded line is reported missing) and passes with the fix.
test_celery, is pre-existing here (celery is not installed) and failsidentically on
main.