0

I have some tests in myproject/core/tests/test_views_front.py. When I try to run python manage.py test myproject.core.tests.test_views_front I get:

NOTE: Using test database settings!
NOTE: Logging is disabled!
Traceback (most recent call last):
  File "manage.py", line 9, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/__in
it__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/__in
it__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/comm
ands/test.py", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/base
.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/comm
ands/test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/base
.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/south/management/commands/t
est.py", line 8, in handle
    super(Command, self).handle(*args, **kwargs)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/comm
ands/test.py", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/test/runner.py", lin
e 144, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/home/ben/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/test/runner.py", lin
e 63, in build_suite
    tests = self.test_loader.loadTestsFromName(label)
  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_front'

This also happens if I run python manage.py test myproject.core.tests.test_views_front.FrontPageViewTests. However, if I simply run python manage.py test or python manage.py test myproject.core.tests then all the tests (including the ones in the aforementioned file) run fine. I found this solution but my test file seems to import fine, without any errors or warnings. Is there anything else I might be missing?

Community
  • 1
  • 1
benwad
  • 6,414
  • 10
  • 59
  • 93

1 Answers1

0

You can't run test from a specific file in Django. You can either run all the test from myproject.core.tests like you did or a specific TestCase:

myproject.core.tests.YourTestCase
Nhor
  • 3,860
  • 6
  • 28
  • 41
  • Ah, I should have clarified that running the specific test case results in the same error (I've updated the question to reflect this). Also, it is possible for me to run all tests for other specific files, so I don't think this is the issue. – benwad Nov 25 '15 at 15:45
  • That's because you still include the file name. Note that Django sees all your tests as an object, so your files structure doesn't matter. Just ignore the file name. – Nhor Nov 25 '15 at 15:47
  • The command `python manage.py test myproject.core.tests.test_views_back` still works though, so this problem appears to be specific to `test_views_front`. – benwad Nov 25 '15 at 16:00