-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include test suite in code coverage #870
Conversation
Rationale: - Tests are code. - Identify tests that aren’t running. - Ensure that test helpers are used and tested. Caveats: - Coverage may require extra configuration if tests are deliberately excluded. - Tests may clutter the coverage report; use `--skip-covered` for this. - The coverage metric generally goes up. https://nedbatchelder.com/blog/202008/you_should_include_your_tests_in_coverage.html
By default, coverage data contains absolute paths for the test suite. During CI, coverage data from various runners is combined in an environment where these paths do not exist. This results in errors like the following: No source for code: '/Users/runner/work/cookiecutter-hypermodern-python-instance/cookiecutter-hypermodern-python-instance/tests/__init__.py'. Aborting report output, consider using -i. The `coverage.paths` setting does not help with the test suite: Unlike the code under `src`, the test suite is not installed to `site-packages`, so we'd need to either hardcode paths from individual runners, or use overly generic wildcards. Instead, `coverage.run.relative_files` can be used to store the paths relative to the repository. We still need `coverage.paths` for `src` though, because these file paths still include the path into the various Nox environments.
affed1b
to
eb31214
Compare
Converted to draft, because for generated projects this fails locally and in CI, see cjolowicz/cookiecutter-hypermodern-python-instance#545 . Looks like this needs some more time to figure out--a minimal repro and digging into Coverage.py's handling of Job log:
|
This appears to have been fixed in Coverage 6.1.2, nedbat/coveragepy#1147. |
The coverage job still fails:
EDIT: Locally the coverage session succeeds when running |
This is apparently triggered when coverage is reported on POSIX for coverage data generated on Windows, due to platform-dependent path separators. The following was run on macOS using the coverage-data artifact from GA:
|
The coverage session succeeds if the coverage data from Windows is removed prior to
|
Superceded by 5c5e256 |
Closes #792
Include the test suite in code coverage, via the coverage.run.source setting.
Rationale:
Caveats:
--skip-covered
for this.https://nedbatchelder.com/blog/202008/you_should_include_your_tests_in_coverage.html
This PR also enables the coverage.run.relative_files setting, to store paths relative to the repository in the coverage data files. By default, coverage data contains absolute paths for the test suite. During CI, coverage data from various runners is combined in an environment where these paths do not exist. This results in errors like the following:
The coverage.paths setting does not help with the test suite: Unlike the code under
src
, the test suite is not installed tosite-packages
, so we'd need to either hardcode paths from individual runners, or use overly generic wildcards. The setting is still needed forsrc
though, because even the relative paths include the location of the various Nox environments.