0

Having followed the advice in these two answers, I'm still unable to run only a single django test in the way it describes. I can run them all, but that takes a long time and makes debugging harder.

My project structure looks like this:

mainapp/mainapp/users/ 
├── __init__.py 
├── tests
│   ├── __init__.py 
│   ├── test_views.py
└── views.py

For example, when the whole test suite is run, one of the failing tests gives this output:

FAIL: test_changepassword (mainapp.users.tests.test_views.ChangePasswordTest)

But when I try to run that Django TestCase with either the Django...

~/mainapp$ python manage.py test mainapp.users.tests.test_views.ChangePasswordTest
File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
        parent, obj = obj, getattr(obj, part) 
AttributeError: 'module' object has no attribute 'test_views'

or django-nose syntax...

~/mainapp$ python manage.py test mainapp.users.tests.test_views:ChangePasswordTest
File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
        parent, obj = obj, getattr(obj, part) 
AttributeError: 'module' object has no attribute 'test_views:ChangePasswordTest'

When I run this in PyCharmCE debug mode it confirms that the module object has no attributes, but I don't know why.

I have django-nose (1.4.5) installed and it's in my INSTALLED_APPS, but I don't know if anything else is required to use it.

This works fine down to a certain level. For example this is OK:

~/mainapp$ python manage.py test mainapp.users.tests

What's going on?

James Bradbury
  • 1,708
  • 1
  • 19
  • 31
  • On a hunch: anything in `mainapp.users.tests.__init__`? Also: can you import `ChangePasswordTest` from the django shell? – CoffeeBasedLifeform Feb 16 '18 at 15:04
  • Nothing in __init__, but importing that from the django shell gives me an import error on ApplicationFactory. Seems odd when these tests work OK from the top level. – James Bradbury Feb 16 '18 at 15:31
  • 1
    Sounds like your problem lies with importing `ApplicationFactory` then. Found [this](https://stackoverflow.com/questions/25575073/attributeerror-module-object-has-no-attribute-tests). – CoffeeBasedLifeform Feb 16 '18 at 16:56

0 Answers0