coverage.py

Test code and branch coverage simultanously with Pytest

Test code and branch coverage simultanously with Pytest Question: I am using pytest to test my Python code. To test for code coverage (C0 coverage) I run pytest –cov and I can specify my desired coverage in my pyproject.toml file like this: [tool.coverage.report] fail_under = 95 I get this result with a coverage a 96.30%: …

Total answers: 1

pytest coverage not working after python update to 3.11

pytest coverage not working after python update to 3.11 Question: Issue: pytest stopped generating coverage Description: I upgraded python version from 3.6 to 3.11 (Ubuntu 18.04). I followed this https://www.debugpoint.com/install-python-3-11-ubuntu/ in order to do that. Had issues with pip, followed this advice: https://stackoverflow.com/a/72685573/15923186 I have a project with following structure: test.sh |-sorting |- env (the …

Total answers: 2

Coverage "No source for code" with pytest

Coverage "No source for code" with pytest Question: I am trying to measure code coverage by my pytest tests. I tried following the quick start guide of coverage (https://coverage.readthedocs.io/en/6.4.1/) When I run my test with the following command, everything seems fine coverage run -m pytest tests/ ===================================== test session starts ====================================== platform linux — Python …

Total answers: 4

Exclude a function from coverage

Exclude a function from coverage Question: I am using coverage.py to get the test coverage of the code. Suppose I have two functions with the same name in two different modules # foo/foo.py def get_something(): # fetch something # 10 line of branch code return "something foo/foo.py" # bar/foo.py def get_something(): # fetch something # …

Total answers: 1

With coverage.py, how to skip coverage of import and def statements

With coverage.py, how to skip coverage of import and def statements Question: I have a python program that imports other files which potentially import other files, as is normal with python development The problem is, when I measure coverage with coverage.py, some files which are imported but not used, get coverage “hits” on the def …

Total answers: 3

Why does Coverage.py ignore files with no coverage?

Why does Coverage.py ignore files with no coverage? Question: I first run nosetests –with-coverage So I should have a .coverage file with all the default settings. Within folder_1, I have file_1.py, file_2.py, and file_3.py When I cd into folder_1 and run coverage report It outputs: It doesn’t generate anything for file_3.py! But then when I …

Total answers: 2

How to properly use coverage.py in Python?

How to properly use coverage.py in Python? Question: I’ve just started using Coverage.py module and so decided to make a simple test to check how it works. Sample.py def sum(num1, num2): return num1 + num2 def sum_only_positive(num1, num2): if num1 > 0 and num2 > 0: return num1 + num2 else: return None test.py from …

Total answers: 4

How do I make coverage include not tested files?

How do I make coverage include not tested files? Question: I have just started writing some unit tests for a python project I have using unittest and coverage. I’m only currently testing a small proportion, but I am trying to work out the code coverage I run my tests and get the coverage using the …

Total answers: 4

Python Code Coverage and Multiprocessing

Python Code Coverage and Multiprocessing Question: I use coveralls in combination with coverage.py to track python code coverage of my testing scripts. I use the following commands: coverage run –parallel-mode –source=mysource –omit=*/stuff/idont/need.py ./mysource/tests/run_all_tests.py coverage combine coveralls –verbose This works quite nicely with the exception of multiprocessing. Code executed by worker pools or child processes is …

Total answers: 3