Code from "Testing Python" book
Via unittest:
python3 -m unittest test/unit/calculator_app/calculate_test.pyVia nose:
nosetestsAll tests via nose:
nosetests test/unit/calculator_app/calculate_test.pynosetests does not run executable files by default, so one should make them non-executable by chmod -x *.py or
explicitly tell nosetests to run executable files by --exe. chmod can not make files at ntfs/fat32 partitions
executable.
Use --rednose to color test results (same name package required).
Via py.test:
py.testPDB:
nosetests --pdb
py.test --pdbPackage nose-cov required:
nosetests --with-coveragePackage pytest-cov:
py.test --cov-report term-missing --cov calculator_app/ test/Generate report:
nosetests --with-coverage --cover-html
py.test --cov-report html --cov calculator_app/ test/Coverage threshold:
nosetests --with-coverage --cov-min-percentage=95To uncover some code:
def func(): #pragma: no coverpy.test --doctest-modules calculator_app/ test/unit/calculator_app/
nosetests --with-doctestI use behave as an alternative to lettuce:
behave bank/test/bdd/features/Specific test by tag:
behave --tags=customer_balance bank/test/bdd/features/Robotframwork:
pybot bank/test/bdd/robot/python -m cProfile -s time run_bank_app.pyVisualization:
pycallgraph graphviz -- run_bank_app.pypylint calculator_app/calculate.py