Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Include test suite in code coverage #520

Closed
staticdev opened this issue Nov 27, 2021 · 0 comments · Fixed by #521
Closed

Include test suite in code coverage #520

staticdev opened this issue Nov 27, 2021 · 0 comments · Fixed by #521
Labels
testing Testing

Comments

@staticdev
Copy link
Owner

Include the test suite in code coverage, via the coverage.run.source setting.

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 if this is an issue.
The coverage metric generally goes up.

See https://nedbatchelder.com/blog/202008/you_should_include_your_tests_in_coverage.html

This PR also updates the coverage.paths setting, to map paths for the test suite to the local source tree. 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.run.relative_files setting is not an option here due to nedbat/coveragepy#991: Windows paths are stored with backslashes, triggering No source errors when the coverage data is combined on other platforms, such as the Ubuntu runner used in our coverage job:

No source for code: '/path/to/cookiecutter-hypermodern-python-instance/tests_init_.py'.

Note the backslash in the filename reported in the error message. If that upstream issue was fixed, we'd still need coverage.paths for src though. This is because relative paths for the installed package still include the location of the various Nox environments.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
testing Testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant