Search code examples
djangodjango-tests

Django Test : __init__() got an unexpected keyword argument 'failfast'


I've a problem with my Django App, this week I added some models and tests but when I'm about to test it with "python manage.py test", I have this error :

TypeError: __init__() got an unexpected keyword argument 'failfast'

I've tried to see if I have some bugs in my models/serializers/tests (syntax error) and even tried to go back to an ancient working commit, but it doesn't solved my issue when testing ... Also, my server work when I'm using "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'

I don't use the failfast argument in the command line so this error makes no sence for me. I use Django 2.2.2 !

Here a snippet of what my tests looks like :

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")

Solution

  • I had the same issue with a django project that had worked on python 2 but mysteriously stopped working when I switched to python 3.

    For me the solution was to switch from the xmlrunner package to unittest-xml-reporting

    I.e. try this :-

    pip3 uninstall xmlrunner
    pip3 install unittest-xml-reporting
    

    The xmlrunner package is no longer supported, unittest-xml-reporting is the replacement.