运行Django测试PyCharm的覆盖范围

时间:2015-05-31 15:01:39

标签: python django testing coverage.py

我是Django的初学者,尤其是测试。由于这是一种最佳实践,我希望我能够实现这一目标......

我刚开始一个项目(称为leden),并制作了我的第一个测试文件 test_initial.py

class test_LidViewTests(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(username='jacob', email='jacob@pils.com', password='top_secret')
        self.client.login(username='jacob', password='top_secret')

def test_view_non_existing_lid(self):
        response = self.client.get(reverse('leden:lid', kwargs={'lid_id': 1}))
        self.assertEqual(response.status_code, 404)

当我使用命令 python manage.py test 运行测试时,所有测试都会运行。当我尝试在PyCharm中运行我的测试时(我使用this教程),我得到以下错误:

/home/mathijs/.virtualenvs/ledenbestand/bin/python3.4 /opt/pycharm-3.4/helpers/pycharm/django_test_manage.py test leden.tests /home/mathijs/Development/ledenbestand
Testing started at 17:00 ...
/home/mathijs/.virtualenvs/ledenbestand/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.unittest will be removed in Django 1.9.
  return f(*args, **kwds)

/home/mathijs/.virtualenvs/ledenbestand/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.unittest will be removed in Django 1.9.
  return f(*args, **kwds)

Traceback (most recent call last):
  File "/opt/pycharm-3.4/helpers/pycharm/django_test_manage.py", line 127, in <module>
    utility.execute()
  File "/opt/pycharm-3.4/helpers/pycharm/django_test_manage.py", line 102, in execute
    PycharmTestCommand().run_from_argv(self.argv)
  File "/home/mathijs/.virtualenvs/ledenbestand/lib/python3.4/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/mathijs/.virtualenvs/ledenbestand/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/mathijs/.virtualenvs/ledenbestand/lib/python3.4/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/home/mathijs/.virtualenvs/ledenbestand/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/opt/pycharm-3.4/helpers/pycharm/django_test_manage.py", line 89, in handle
    failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive, failfast=failfast)
  File "/opt/pycharm-3.4/helpers/pycharm/django_test_runner.py", line 228, in run_tests
    extra_tests=extra_tests, **options)
  File "/opt/pycharm-3.4/helpers/pycharm/django_test_runner.py", line 128, in run_tests
    return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
AttributeError: 'super' object has no attribute 'run_tests'

你们有什么想法我能解决这个问题吗?

1 个答案:

答案 0 :(得分:4)

看起来PyCharm v4.0 +中存在一些已知问题,在使用Django v1.8时导致此错误消息:

问题14401现在在几个内部版本中被标记为已修复,但是不清楚PyCharm的哪个版本将获得修复。