我使用 Django 框架创建基本的 Web 应用程序。我开始为我的观点编写测试。我遵循 django 文档并解决了一些问题。但现在我陷入了困境 - 即使在搜索答案 30 分钟后我也不知道为什么会收到此错误。
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
我的测试.py 看起来像这样:
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)
我使用 python 3.11 和 django 5.0a1。有人有线索吗?我认为它与设置有某种联系,但我不知道如何。
Django 在 Django 5.0 中删除了参数
extra_tests
,并且 PyCharm
的测试运行程序仍然提供它。
参见 django 的发行说明:
DiscoverRunner.build_suite() 和 DiscoverRunner.run_tests() 的 extra_tests 参数已删除。
您可以降级到 django 4.2,直到此问题得到解决。
存在与此弃用相关的 Pycharm 问题,请参阅 PY-53355。