我在myproject/core/tests/test_views_front.py
进行了一些测试。当我尝试运行python manage.py test myproject.core.tests.test_views_front
时,我得到:
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'
如果我运行python manage.py test myproject.core.tests.test_views_front.FrontPageViewTests
,也会发生这种情况。但是,如果我只是运行python manage.py test
或python manage.py test myproject.core.tests
,则所有测试(包括上述文件中的测试)都可以正常运行。我找到了this解决方案,但我的测试文件似乎导入正常,没有任何错误或警告。还有什么我可能会遗失的吗?
答案 0 :(得分:0)
您无法在Django中的特定文件中运行测试。您可以像{01}一样运行所有测试,也可以像特定的myproject.core.tests
一样运行
TestCase