【发布时间】:2019-11-26 00:12:30
【问题描述】:
我的 Django 应用有问题,这周我添加了一些模型和测试,但是当我要使用 "python manage.py test" 对其进行测试时,我遇到了这个错误:
TypeError: __init__() got an unexpected keyword argument 'failfast'
我尝试查看我的模型/序列化程序/测试中是否有一些错误(语法错误),甚至尝试返回到一个古老的工作提交,但它在测试时并没有解决我的问题...... 另外,当我使用 "python manage.py runserver".
时,我的服务器工作正常Creating test database for alias 'default'...
System check identified no issues (0 silenced).
Destroying test database for alias 'default'...
Traceback (most recent call last):
File "manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Arh\.virtualenvs\mybacksentinhealth-gHbH4SRy\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Arh\.virtualenvs\mybacksentinhealth-gHbH4SRy\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Arh\.virtualenvs\mybacksentinhealth-gHbH4SRy\lib\site-packages\django\core\management\commands\test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "C:\Users\Arh\.virtualenvs\mybacksentinhealth-gHbH4SRy\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Arh\.virtualenvs\mybacksentinhealth-gHbH4SRy\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\Arh\.virtualenvs\mybacksentinhealth-gHbH4SRy\lib\site-packages\django\core\management\commands\test.py", line 53, in handle
failures = test_runner.run_tests(test_labels)
File "C:\Users\Arh\.virtualenvs\mybacksentinhealth-gHbH4SRy\lib\site-packages\django\test\runner.py", line 633, in run_tests
result = self.run_suite(suite)
File "C:\Users\Arh\.virtualenvs\mybacksentinhealth-gHbH4SRy\lib\site-packages\xmlrunner\extra\djangotestrunner.py", line 57, in run_suite
runner = self.test_runner(**runner_kwargs)
TypeError: __init__() got an unexpected keyword argument 'failfast'
我不在命令行中使用 failfast 参数,所以这个错误对我来说毫无意义。 我使用 Django 2.2.2 !
这里是我的测试的样子:
import pytz
from logging import info
from django.test import TestCase
from django.utils import timezone
from django.test import TransactionTestCase
from apps.myheart.api.api_acquisitions_markers import acquisitions_markers_get
from apps.myheart.models import Implants, Markers, AcquisitionsMarkers, Acquisitions
from datetime import timedelta, datetime
from .test_authentication import authenticate
class ImplantsAPIViewTestCase(TransactionTestCase):
def setUp(self):
self.implant1 = Implants.objects.create(
num=1, implantation_date=datetime(2012, 11, 20, 20, 8, 7, 127325, tzinfo=pytz.UTC), implantation_hopital="hopital1"
)
self.implant2 = Implants.objects.create(
num=2, implantation_date=datetime(2014, 11, 18, 20, 8, 7, 127325, tzinfo=pytz.UTC), implantation_hopital="hopital2"
)
self.implant3 = Implants.objects.create(
num=34, implantation_date=datetime(2016, 10, 18, 20, 8, 7, 127325, tzinfo=pytz.UTC), implantation_hopital="hopital1"
)
self.token = authenticate()
self.nb_imp = len(Implants.objects.all())
def test_implants_get(self):
info("Test /api/implants/\n")
response = self.client.get("/api/implants/", HTTP_AUTHORIZATION=self.token)
info(response.data)
# We need to check that we have all the files presents in DB
self.assertEqual(len(response.data), self.nb_imp)
info("\n")
【问题讨论】:
-
您是否更改了 testrunner 上的某些内容或与 TestCase 类 SetUp 相关的任何内容?我的意思是,我只是在这里在黑暗中拍摄。
-
我没有更改包中的任何代码,甚至尝试将所有这些(我正在使用 pipenv)重新安装到工作版本。我正在向我的问题添加一个关于我的测试是什么样子的 sn-p。
标签: django django-tests