pythondjangotestingpycharm

Django testing views - getting error - DiscoverRunner.run_tests() takes 2 positional arguments but 3 were given


I use Django framework to create basic web application. I started to write tests for my views. I followed the django documentation and fixed some issues along the way. But now I am stuck - I don't know why I get this error even after 30 minutes of searching for answer.

    C:\Osobni\realityAuctionClient\venv\Scripts\python.exe "C:/Program Files/JetBrains/PyCharm 2022.3.3/plugins/python/helpers/pycharm/django_test_manage.py" test realityAuctionClientWeb.test_views.TestViews.test_start_view C:\Osobni\realityAuctionClient 
Testing started at 7:41 ...
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2022.3.3\plugins\python\helpers\pycharm\django_test_manage.py", line 168, in <module>
    utility.execute()
  File "C:\Program Files\JetBrains\PyCharm 2022.3.3\plugins\python\helpers\pycharm\django_test_manage.py", line 142, in execute
    _create_command().run_from_argv(self.argv)
  File "C:\Osobni\realityAuctionClient\venv\Lib\site-packages\django\core\management\commands\test.py", line 24, in run_from_argv
    super().run_from_argv(argv)
  File "C:\Osobni\realityAuctionClient\venv\Lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Osobni\realityAuctionClient\venv\Lib\site-packages\django\core\management\base.py", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\JetBrains\PyCharm 2022.3.3\plugins\python\helpers\pycharm\django_test_manage.py", line 104, in handle
    failures = TestRunner(test_labels, **options)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\JetBrains\PyCharm 2022.3.3\plugins\python\helpers\pycharm\django_test_runner.py", line 254, in run_tests
    return DjangoTeamcityTestRunner(**options).run_tests(test_labels,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\JetBrains\PyCharm 2022.3.3\plugins\python\helpers\pycharm\django_test_runner.py", line 156, in run_tests
    return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: DiscoverRunner.run_tests() takes 2 positional arguments but 3 were given

Process finished with exit code 1

Empty suite

My tests.py looks like this:

 import django
from django.test import TestCase
from django.urls import reverse


class TestViews(TestCase):

    def test_start_view(self):
        """
        Test that the start view returns a 200 response and uses the correct template
        """
        django.setup()
        url = reverse("start")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 200)

I use python 3.11 and django 5.0a1. Anybody who has a clue? I think it is somehow connected with settings but I do not know how.


Solution

  • Django removed the parameter extra_tests in Django 5.0 and PyCharm's test runner is still providing it.

    See django's release notes:

    The extra_tests argument for DiscoverRunner.build_suite() and DiscoverRunner.run_tests() is removed.

    You could downgrade to django 4.2 until this is fixed by Jetbrains.

    A Pycharm issue regarding this deprecation exists, see PY-53355.