2

I'm getting an error when trying to run an individual TestCase using django-nose

$ ./manage.py test someapp.ModelTest
nosetests someapp.ModelTest --nologcapture --verbosity=1
Creating test database for alias 'default'...
E
======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'ModelTest')
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python2.7/site-packages/nose/loader.py", line 402, in loadTestsFromName
    module = resolve_name(addr.module)
 File "/usr/lib/python2.7/site-packages/nose/util.py", line 321, in resolve_name
    obj = getattr(obj, part)
AttributeError: 'module' object has no attribute 'ModelTest'

----------------------------------------------------------------------
Ran 1 test in 0.003s

FAILED (errors=1)

Note that when I run $ ./manage.py test someapp it successfully runs all of the TestCases in someapp/tests.py; only when trying to run an individual TestCase does it fail.

Will
  • 187
  • 6
  • It's simply an import error but it's impossible to know where your problem is without seeing the rest of the code. I would imagine you have a messed up import in your models, admin or views file? – Chris Hawkes Oct 22 '13 at 19:34
  • possible duplicate of [How to run a single test or single TestCase with django-nose?](http://stackoverflow.com/questions/18834188/how-to-run-a-single-test-or-single-testcase-with-django-nose) – kolen May 21 '15 at 19:00

1 Answers1

5

If you're using nose, type in the name of the module (normally tests), a colon, and the test class

manage.py test someapp.tests:SomeTestClass

<path_to_python_module>:<class_name>

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245
  • Excellent, thank you! I was somehow under the impression that because `./manage.py test someapp` worked as expected, that it was still Django's test runner deciding what tests to run, and not nose. – Will Oct 23 '13 at 14:44
  • Does not work for me — imports became broken. ``sys.path`` contains directory of project, but the first import in ``somaapp.admin.py`` (the same app as containing specified test) causes ``ImportError``. – kolen May 21 '15 at 18:38