简体   繁体   English

运行Django测试PyCharm的覆盖范围

[英]Run Django tests PyCharm with coverage

I'm quite a beginner with Django, especially with testing. 我是Django的初学者,尤其是测试。 Since it is a best practice, I hope I can get this up and running... 由于这是一种最佳实践,我希望我能够实现这一目标......

I just started a project (called leden), and made my first testfile test_initial.py . 我刚开始一个项目(称为leden),并制作了我的第一个testfile 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)

When I run the tests with the command python manage.py test , all tests are run. 当我使用命令python manage.py test运行测试时 ,将运行所有测试。 When I try to run my tests in PyCharm however (I used this tutorial), I get the following errors: 当我尝试在PyCharm中运行我的测试时(我使用教程),我收到以下错误:

/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'

Do you guys have any idea how I can fix this? 你们有什么想法我能解决这个问题吗?

It looks like there are a couple of known issues in PyCharm v4.0+ which cause this error message when using Django v1.8: 看起来PyCharm v4.0 +中存在一些已知问题,这些问题在使用Django v1.8时会导致出现此错误消息:

Issue 14401 is now marked as fixed in a couple of internal builds, but it's not clear which release version of PyCharm will get the fix. 问题14401现在在几个内部版本中被标记为已修复,但目前尚不清楚PyCharm的哪个版本将获得修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM