Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#21089 closed Bug (fixed)

TestCase can't define an empty list of fixtures

Reported by: lgs Owned by: nobody
Component: Testing framework Version: 1.5
Severity: Normal Keywords: fixtures
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


This could be useful if you have a TestCase base class that define some very basic fixtures that are used across all your tests but then, there is a few particular tests that do not want such fixtures.

Let's say you have something like:

class BaseTestCase(TestCase):

  fixtures = ['basic_data.json']

class NoFixturesTestCase(BaseTestCase):

  fixtures = []

If you do this you will get this error:

Traceback (most recent call last):
  File "/home/lgs/proyectos/personal/django/django/test/", line 173, in __call__
  File "/home/lgs/proyectos/personal/django/django/test/", line 716, in _pre_setup
  File "/home/lgs/proyectos/personal/django/django/test/", line 848, in _fixture_setup
    'skip_validation': True,
  File "/home/lgs/proyectos/personal/django/django/core/management/", line 159, in call_command
    return klass.execute(*args, **defaults)
  File "/home/lgs/proyectos/personal/django/django/core/management/", line 289, in execute
    output = self.handle(*args, **options)
  File "/home/lgs/proyectos/personal/django/django/core/management/commands/", line 49, in handle
    "No database fixture specified. Please provide the path "
CommandError: No database fixture specified. Please provide the path of at least one fixture in the command line.

You can use this hack as a workaround:

class NoFixturesTestCase(BaseTestCase):

  fixtures = ['non-existing-file.json']

And now you will get a warning instead of an error.

I'll create a Github branch with a test showing this behaviour and a fix for it.

Attachments (1)

ticket-21089.diff (2.2 KB) - added by bmispelon 3 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 3 years ago by mjtamlyn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Is this problem solved by setting fixtures = None?

comment:2 Changed 3 years ago by lgs

No, it is not solved by setting fixtures = None

The Github branch with the testcase to reproduce this error and the fix is located at:

comment:3 Changed 3 years ago by lgs

  • Has patch set

comment:4 Changed 3 years ago by bmispelon

  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

This looks useful, but I have some questions about the patch.

Is there a particular reason that we're using getattr instead of simply defining a fixtures attribute on TransactionTestCase (see attached diff)?

Changed 3 years ago by bmispelon

comment:5 Changed 3 years ago by lgs

I don't know about the reasons behind getattr. That code was there before, I just added an extra check. Your patch would work too so I can update my branch if that option is preferred.

Last edited 3 years ago by lgs (previous) (diff)

comment:6 Changed 3 years ago by Baptiste Mispelon <bmispelon@…>

  • Resolution set to fixed
  • Status changed from new to closed

In abb10db06fb2ecb3e897462ec72417d10b39b8a4:

Fixed #21089 -- Allow TransactionTestcase subclasses to define an empty list of fixtures.

Thanks to lgs for the report and initial patch.

comment:7 Changed 3 years ago by lgs

Thanks for fixing this so fast :-)

Note: See TracTickets for help on using tickets.
Back to Top