The codebase for a Python project of mine contains lots of tests. These tests are broad and capacious enough that I would call them “robust”. I would like to know exactly how robust they are, so I have set up the coverage.py
tool , and a codecov.io account .
The project has two types of tests:
pytest
– ie there are no legacy unittest
-based tests, and pytest
fixtures and hooks are heavily leveraged.# -*- coding: utf-8 -*-
import sys # …etc
# «module code»
def test():
from clu.testing.utils import inline
@inline.precheck
def show_some_initial_values():
""" Precheck function description """
# «pre-check code»
@inline
def test_one():
""" Test one’s description """
# «test code»
@inline
def test_two():
""" Test two’s description """
# «test code»
@inline.diagnostic
def show_some_final_values():
""" Diagnostic function description """
# «post-run diagnostic code»
return inline.test(100) # runs test functions 100 times;
# prechecks and diagnostics run once
if __name__ == '__main__':
sys.exit(test())
… and they output reports like so:
… The inline tests can be run on a per-module basis, right from the editor. They can also all be run en masse via a nox
setup that collects and runs all modules that define inline tests .
So now, regarding coverage.py
and codecov.io – it was extremely easy to integrate the pytest
suite with these tools. I made a few tweaks to an off-the-shelf .coveragerc
file, installed the pytest
codecov.io plugin, and that was that – those tests report their coverage to codecov.io just fine.
My question is, how do I integrate coverage reporting for the inline tests?
coverage.py
to “understand” these test functions, or do the inline tests need to report their results to the coverage tool(s)?.coveragerc
file, or is it more involved?Coverage.py doesn't understand anything about tests. All it does is tell you what parts of your code were run by some program. Usually that program is a test runner, but coverage.py doesn't care.
If you run your tests now with python mytestrunner.py
, change the command to coverage run mytestrunner.py
, and you will get data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.