There are difference between ‘building it right’ and ‘building the right thing’. -Python Testing Cookbook by Greg L. Turnquist
Run All unittest in module:
python -m unittest discover <test_module>
# ubuntu install python3-pip first
# $ sudo apt-get install python3-ip
$ pip3 install nose
$ nosetests-3.x
Problems using nose in a virtualenv
you can’t run nose in system-packages to using packages in virtualenv (sandbox)
Run PDB with nosetest:
from nose.tools import set_trace; set_trace()
You should make unittest run faster with mocking better than using multi processes.
There are many problem with nose plugin ex. rednose, coverage, xunit.
In worst case more processeses can make your tests slower depends on your tests.
$ nosetests --processes=NUMBER_OF_PROCESSORS --process-timeout <sec>
Stmts - statements
Miss - statements that not executed
Cover - (Stmts - Miss)/Stmts * 100
nosetests --with-coverage --cover-html
Coverage erase
coverage erase
coverage -e
nosetests --with-coverage --cover-erase
Coverage with filter Third-party Libraries out
nosetests --with-coverage --cover-package=<package,package2>
nosetests --with-coverage --cover-package=$(ls | grep '.py$' | sed 's/[.]py$//' | xargs | sed 's/[\ ]/,/g')
mocking pattern
1.record/replay pattern
2.action/assert pattern
BDD Stroy
-Feature
– Scenario
— steps
pip install nose rednose coverage
echo "export NOSE_REDNOSE=1" >> .zshrc #enable rednose
pip install watchdog
pip install tox