How do I specify a single test in a file with nosetests?

opstastic picture opstastic · Jul 2, 2012 · Viewed 33.5k times · Source

I have a file called test_web.py containing a class TestWeb and many methods named like test_something().

I can run every test in the class like so:

$ nosetests test_web.py 
...
======================================================================
FAIL: checkout test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/me/path/here/test_web.py", line 187, in test_checkout
...

But I can’t seem to run individual tests. These give me “No such test” errors when run in the same PWD:

$ nosetests test_web.py:test_checkout
$ nosetests TestWeb:test_checkout

What could be wrong here?

Answer

Will picture Will · Jul 2, 2012

You must specify it like so: nosetests <file>:<Test_Case>.<test_method>, or

nosetests test_web.py:TestWeb.test_checkout

See the docs