简体   繁体   中英

Run Django tests PyCharm with coverage

I'm quite a beginner with Django, especially with testing. 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 .

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. When I try to run my tests in PyCharm however (I used this tutorial), I get the following errors:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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