Django 测试:__init__() 得到了一个意外的关键字参数 'failfast'
Django Test : __init__() got an unexpected keyword argument 'failfast'
我的 Django 应用程序有问题,这周我添加了一些模型和测试,但是当我要使用 "python manage.py test" 对其进行测试时,我有这个错误:
TypeError: __init__() got an unexpected keyword argument 'failfast'
我试图查看我的 models/serializers/tests 中是否有一些错误(语法错误),甚至试图返回到一个古老的工作提交,但它并没有解决我在测试时遇到的问题。 ..
另外,我的服务器在我使用 "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")
我刚刚发现了我的错误,似乎是 XMLRunner 和 unittest-xml-reporting 向我报告了这个错误。因为我已经使用了它们一段时间并且效果很好我不知道为什么它们不再起作用但是删除它们修复了它。
我在 python 2 上工作的 django 项目遇到了同样的问题,但当我切换到 python 3 时神秘地停止工作。
对我来说,解决方案是从 xmlrunner package to unittest-xml-reporting
切换
即试试这个:-
pip3 uninstall xmlrunner
pip3 install unittest-xml-reporting
不再支持 xmlrunner 包,unittest-xml-reporting 是替代品。
Django 测试:init() 得到了一个意外的关键字参数 'failfast'
在这个网站的帮助下,我花了一些时间才弄明白这一点。为 pipenv 添加答案。
pipenv uninstall xmlrunner
pipenv install unittest-xml-reporting
我的 Django 应用程序有问题,这周我添加了一些模型和测试,但是当我要使用 "python manage.py test" 对其进行测试时,我有这个错误:
TypeError: __init__() got an unexpected keyword argument 'failfast'
我试图查看我的 models/serializers/tests 中是否有一些错误(语法错误),甚至试图返回到一个古老的工作提交,但它并没有解决我在测试时遇到的问题。 .. 另外,我的服务器在我使用 "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")
我刚刚发现了我的错误,似乎是 XMLRunner 和 unittest-xml-reporting 向我报告了这个错误。因为我已经使用了它们一段时间并且效果很好我不知道为什么它们不再起作用但是删除它们修复了它。
我在 python 2 上工作的 django 项目遇到了同样的问题,但当我切换到 python 3 时神秘地停止工作。
对我来说,解决方案是从 xmlrunner package to unittest-xml-reporting
切换即试试这个:-
pip3 uninstall xmlrunner
pip3 install unittest-xml-reporting
不再支持 xmlrunner 包,unittest-xml-reporting 是替代品。
Django 测试:init() 得到了一个意外的关键字参数 'failfast' 在这个网站的帮助下,我花了一些时间才弄明白这一点。为 pipenv 添加答案。
pipenv uninstall xmlrunner
pipenv install unittest-xml-reporting