pytest-project-setup
This is a pytest project setup
Note on Codespaces Virtualenv
Checkout how if you run pip freeze | wc -l there are many packages we may not want
Try which python
virtualenv ~/.venv- Always source this virt env:
vim ~/.bashrcand put insource ~/.venv/bin/activate - Verify the right python
which pythonand trypip freeze | wc -lit should be 0
Make file
make installinstall the project dependenciesmake testperform tests execution and coverage statmake formatformatting the codemake lintstatic code validationmake allperform all operations (from step 1 to step 4) one after each other
Dummy user cli function for testing purposes
python src/user.pyreturn the default greetingHello guest user!python src/user.py --user=superadminreturn the greeting with custom user valueHello superadmin user!
Pytest execution
- Library style:
python -m pytest -vv --cov=src testing/ - Run tests by keyword expressions:
python -m pytest -vv -k "user" - Run a specific test within a modele:
python -m pytest testing/test_user.py::test_random_user - Run tests by marker expressions:
https://docs.pytest.org/en/7.2.x/how-to/usage.html#usage - Profile tests:
python -m pytest -vv --durations=10 --durations-min=1.0 - Distributed testing
https://pypi.org/project/pytest-xdist/
On this page
Languages
Python81.4%Makefile18.6%
Contributors
Creative Commons Zero v1.0 Universal
Created November 14, 2022
Updated November 18, 2022