Skip to content

Python Notes

shamik edited this page Apr 25, 2024 · 1 revision

Code Coverage

Run coverage and pytest together for all the dirs

cd to the directory and then enter coverage run -m pytest

Running the same coverage but ommitting certain dir

coverage run --omit="<dir>" -m pytest

Below is an example of the same omitting test dir coverage run --omit="tests/*" -m pytest

Generate html report for code coverage in a specified directory. For eg. If the directory is coverage the code below will work

coverage html -d ../../coverage/

With a title for the HTML

coverage html --title "Whatever floats your boat"

Checking the coverage report omitting test dir and with all the missing lines

coverage report --omit="tests/*"

Run pytest for a single file

pytest tests/xml_parser/xml_parser_test.py

Run pytest by ignoring certain tests in certain folders

pytest --ignore=tests/summarization/ --ignore=tests/test_utils/ tests/

Running a single unit test through python

python common/test/common/anlpModels/ESGNumExtract/number_extraction_test.py NumberExtractionTest.test_save_model

Running a single unit test through pytest

pytest common/test/common/anlpModels/ESGNumExtract/number_extraction_test.py::NumberExtractionTest::test_save_model

Printing objects to console in pytest

pytest -s common/test/common/anlpModels/ESGNumExtract/number_extraction_test.py

Encodings

Codecs