Generic problems with solutions and tests in Python.
- Python >= 3.0
- Coverage
Install pytest:
pip install pytest
Run all tests:
pytest
Stop pytest after first failure
pytest -x
Run single unit test:
pytest <path_to_file.py>
Es:
pytest tests/algorithms/strings/test_stringutil.py
Install coverage:
pip install coverage
Show coverage:
coverage run --source=src/ -m pytest
Using pytest-cov. Install it:
pip install pytest-cov
Show coverage
pytest --cov=src tests/
Generate HTML reports:
coverage run --source=src/ -m pytest
coverage html
Coverage has a problem: it doesn't generate a report for files without test so I use pytest-cov:
pytest --cov=src tests/ --cov-report=html
pylint src --disable=missing-docstring && pylint test --disable=missing-docstring
pip freeze > requirements.txt