I have a Pylons 1.0 app with a bunch of tests in the test/functional directory. I'm getting weird test results and I want to just run a single test. The nose documentation says I should be able to pass in a test name at the command line but I get ImportErrors no matter what I do
For example:
nosetests -x -s sometestname
Gives:
Traceback (most recent call last):
File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/loader.py", line 371, in loadTestsFromName
module = resolve_name(addr.module)
File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/util.py", line 334, in resolve_name
module = __import__('.'.join(parts_copy))
ImportError: No module named sometestname
I get the same error for
nosetests -x -s appname.tests.functional.testcontroller
What is the correct syntax?
nosetests appname.tests.functional.test_controller
should work, where the file is namedtest_controller.py
.To run a specific test class and method use a path of the form
module.path:ClassNameInFile.method_name
, that is, with a colon separating the module/file path and the objects within the file.module.path
is the relative path to the file (e.g.tests/my_tests.py:ClassNameInFile.method_name
).I have to add the ".py" file extension, that is,
Maybe this is because I don't have any classes in the file. Without the
.py
, nose was complaining:And this although I have an
__init__.py
in the folder/path_to/
.For me using Nosetests 1.3.0 these variants are working (but make sure you have
__init__.py
in your tests folder):Note that single colon between module name and class name.
I wrote this small script, based on the previous answers: