Skip to content

Python Notes

Shamik edited this page Mar 19, 2026 · 2 revisions

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

Install pre-commit config

pre-commit install -c ../../../.pre-commit-config.yaml

To skip certain pre-commit while git commit

Here am skipping mypy

SKIP=mypy git commit -m "feat: archived the old scraper."

### Skipping multiple pre-commit hooks
```sh
SKIP=black,trailing-whitespace,end-of-file-fixer,…

marimo file autocomplete in bash

# Enable file completion for uvx

complete -o default uvx

uvx marimo alias

alias mam="uvx --python 3.12 marimo -y edit  --sandbox --watch"

Clone this wiki locally