Skip to content
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 #545

Merged
merged 2 commits into from Nov 23, 2021
Merged

Include test suite in code coverage #545

merged 2 commits into from Nov 23, 2021

Conversation

cjolowicz
Copy link
Owner

@cjolowicz cjolowicz commented Apr 15, 2021

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant