[Django] #21089: TestCase can't define an empty list of fixtures

8 views
Skip to first unread message

Django

unread,
Sep 11, 2013, 7:21:49 AM9/11/13
to django-...@googlegroups.com
#21089: TestCase can't define an empty list of fixtures
-----------------------------------+----------------------
Reporter: lgs | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Keywords: fixtures
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+----------------------
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/testcases.py",
line 173, in __call__
self._pre_setup()
File "/home/lgs/proyectos/personal/django/django/test/testcases.py",
line 716, in _pre_setup
self._fixture_setup()
File "/home/lgs/proyectos/personal/django/django/test/testcases.py",
line 848, in _fixture_setup
'skip_validation': True,
File
"/home/lgs/proyectos/personal/django/django/core/management/__init__.py",
line 159, in call_command
return klass.execute(*args, **defaults)
File
"/home/lgs/proyectos/personal/django/django/core/management/base.py", line
289, in execute
output = self.handle(*args, **options)
File
"/home/lgs/proyectos/personal/django/django/core/management/commands/loaddata.py",
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/21089>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 11, 2013, 7:30:58 AM9/11/13
to django-...@googlegroups.com
#21089: TestCase can't define an empty list of fixtures
-----------------------------------+--------------------------------------

Reporter: lgs | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:

Keywords: fixtures | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by mjtamlyn):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Is this problem solved by setting `fixtures = None`?

--
Ticket URL: <https://code.djangoproject.com/ticket/21089#comment:1>

Django

unread,
Sep 11, 2013, 7:41:17 AM9/11/13
to django-...@googlegroups.com
#21089: TestCase can't define an empty list of fixtures
-----------------------------------+--------------------------------------

Reporter: lgs | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:

Keywords: fixtures | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (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: https://github.com/lorenzogil/django/compare/ticket_21089

--
Ticket URL: <https://code.djangoproject.com/ticket/21089#comment:2>

Django

unread,
Sep 11, 2013, 7:45:11 AM9/11/13
to django-...@googlegroups.com
#21089: TestCase can't define an empty list of fixtures
-----------------------------------+--------------------------------------

Reporter: lgs | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:

Keywords: fixtures | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by lgs):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/21089#comment:3>

Django

unread,
Sep 11, 2013, 8:03:23 AM9/11/13
to django-...@googlegroups.com
#21089: TestCase can't define an empty list of fixtures
-----------------------------------+------------------------------------

Reporter: lgs | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:
Keywords: fixtures | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by bmispelon):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/21089#comment:4>

Django

unread,
Sep 11, 2013, 8:42:47 AM9/11/13
to django-...@googlegroups.com
#21089: TestCase can't define an empty list of fixtures
-----------------------------------+------------------------------------

Reporter: lgs | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.5
Severity: Normal | Resolution:
Keywords: fixtures | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by lgs):

I don't know about the reasons behind getattr. That code was there before,
I just added an extra check.

--
Ticket URL: <https://code.djangoproject.com/ticket/21089#comment:5>

Django

unread,
Sep 11, 2013, 9:29:13 AM9/11/13
to django-...@googlegroups.com
#21089: TestCase can't define an empty list of fixtures
-----------------------------------+------------------------------------
Reporter: lgs | Owner: nobody
Type: Bug | Status: closed

Component: Testing framework | Version: 1.5
Severity: Normal | Resolution: fixed

Keywords: fixtures | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Baptiste Mispelon <bmispelon@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"abb10db06fb2ecb3e897462ec72417d10b39b8a4"]:
{{{
#!CommitTicketReference repository=""
revision="abb10db06fb2ecb3e897462ec72417d10b39b8a4"
Fixed #21089 -- Allow TransactionTestcase subclasses to define an empty
list of fixtures.

Thanks to lgs for the report and initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21089#comment:6>

Django

unread,
Sep 11, 2013, 10:13:00 AM9/11/13
to django-...@googlegroups.com
#21089: TestCase can't define an empty list of fixtures
-----------------------------------+------------------------------------
Reporter: lgs | Owner: nobody
Type: Bug | Status: closed

Component: Testing framework | Version: 1.5
Severity: Normal | Resolution: fixed
Keywords: fixtures | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by lgs):

Thanks for fixing this so fast :-)

--
Ticket URL: <https://code.djangoproject.com/ticket/21089#comment:7>

Reply all
Reply to author
Forward
0 new messages