To use:
- Install pytest if not already installed.
pip install pytest
- Clone the repo.
git clone https://github.com/allenrobel/pytest-toi.git
- cd into the local clone.
cd pytest-toi
- Run the testcases
pytest
- To run a specific test case:
pytest -k test_monkeypatch_baz
-
Have a look in the coverage.bash script for details on how to use it to generate a coverage report for the example code in this repo.
-
Run coverage.bash (modify as needed depending on your local repo path)
From the report, you should see that:
- The following have complete coverage:
modules/baz.py modules/square.py
- The following are missing coverage for the mocked function send_request(), as expected:
modules/foo.py modules/bar.py
Sometimes it's useful to see what the coverage is for a single test case, or set of test cases.
This can answer the question "Is this testcase really doing anything?"
Below we run the test case in tests/test_parametrize_1.py
rm -rf /tmp/pytest-toi
coverage run --source=./modules -m pytest tests/test_parametrize_1.py
coverage report --show-missing | grep '^Name\|square'
# output removed....
Name Stmts Miss Cover Missing
modules/square.py 5 2 60% 3
The coverage report shows that raise
in modules/square.py (line 3) is not covered, as expected.
If we rerun coverage for tests/test_parametrize_2.py, we see the raise
is covered.
The text report below is actually not correct (Miss should be 0 and Cover 100%).
Looking at the html report shows that all lines ARE covered. Looks like a bug with coverage tool :-(
rm -rf /tmp/pytest-toi
coverage run --source=./modules -m pytest tests/test_parametrize_2.py
coverage report --show-missing | grep '^Name\|square'
# output removed....
Name Stmts Miss Cover Missing
modules/square.py 5 1 80%