I have a directory tests
that includes a lot of different tests named test_*
.
I tried to run coverage run tests
but it doesn't work.
How can I run a single command to coverage multiple files in the directory?
On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.
Increase coverage by adding more tests The code coverage has increased to 78% on adding another test case. It can be increased further to 100% in a similar fashion.
Here is a complete example with commands from the same PWD for all phases in one place. With a worked up example, I am also including the testing and the report part for before and after coverage is run. I ran the following steps and it worked all fine on osx/mojave.
- Discover and run all tests in the test directory
$
python -m unittest discover <directory_name>
Or Discover and run all tests in "directory" with tests having file name pattern *_test.py
$
python -m unittest discover -s <directory> -p '*_test.py'
- run coverage for all modules
$
coverage run --source=./test -m unittest discover -s <directory>/
- get the coverage report from the same directory - no need to cd.
$
coverage report -m
Notice in above examples that the test directory doesn't have to be named "test" and same goes for the test modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With