我的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")
答案 0 :(得分:0)
我刚刚找到了我的错误,似乎是XMLRunner和unittest-xml-reporting向我报告了此错误。由于我使用它们已有一段时间了,所以效果很好,我不知道为什么现在不工作了,但是删除它们可以解决问题。
答案 1 :(得分:0)
我在django项目中遇到过与python 2相同的问题,但是当我切换到python 3时神秘地停止了工作。
对我来说,解决方案是从xmlrunner包切换到unittest-xml-reporting
即试试这个:-
biClrUsed
不再支持xmlrunner软件包,替换为unittest-xml-reporting。
答案 2 :(得分:0)
Django测试: init ()获得了意外的关键字参数'failfast' 我花了点时间在这个站点的帮助下弄清楚了这一点。为pipenv添加答案。 pipenv卸载xmlrunner pipenv安装unittest-xml-报告