Running unit tests in Python

Install nose:
sudo easy_install nose
sudo pip install nose

By default nose finds all directories and files that match the following regular expression:
(?:^|[b_./-])[Tt]est [NOSE_TESTMATCH]

I usually create a file and place my unit tests there as regular functions, e.g.:
def test_function_1():

To run tests in specific file do:

To run all tests in files satisfying regex above:

By default, nose will capture all output sent to stdout. To be able to see print statements inside test functions use –nocapture option.

I usually run all tests by:
nosetests --nocapture -v

nosetests --nocapture -v -w path_to_folder

This entry was posted in Productivity, Programming, Python, UNIX/Linux. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s