Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Repository files navigation

testing_python_book

Code from "Testing Python" book

To run tests

Via unittest:

python3 -m unittest test/unit/calculator_app/calculate_test.py

Via nose:

nosetests

All tests via nose:

nosetests test/unit/calculator_app/calculate_test.py

nosetests 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.test

To debug

PDB:

nosetests --pdb
py.test --pdb

To check test coverage

Package nose-cov required:

nosetests --with-coverage

Package 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=95

To uncover some code:

def func():  #pragma: no cover

To run doctests

py.test --doctest-modules calculator_app/ test/unit/calculator_app/
nosetests --with-doctest

To run acceptance tests

I 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/

Profiling

python -m cProfile -s time run_bank_app.py

Visualization:

pycallgraph graphviz -- run_bank_app.py

Code validation

pylint calculator_app/calculate.py

About

code from "Testing Python" book

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages