Fixed #21089 -- Allow TransactionTestcase subclasses to define an empty list of fixtures.
Thanks to lgs for the report and initial patch.
This commit is contained in:
parent
170f721367
commit
abb10db06f
|
@ -699,6 +699,9 @@ class TransactionTestCase(SimpleTestCase):
|
||||||
# Subclasses can enable only a subset of apps for faster tests
|
# Subclasses can enable only a subset of apps for faster tests
|
||||||
available_apps = None
|
available_apps = None
|
||||||
|
|
||||||
|
# Subclasses can define fixtures which will be automatically installed.
|
||||||
|
fixtures = None
|
||||||
|
|
||||||
def _pre_setup(self):
|
def _pre_setup(self):
|
||||||
"""Performs any pre-test setup. This includes:
|
"""Performs any pre-test setup. This includes:
|
||||||
|
|
||||||
|
@ -746,7 +749,7 @@ class TransactionTestCase(SimpleTestCase):
|
||||||
if self.reset_sequences:
|
if self.reset_sequences:
|
||||||
self._reset_sequences(db_name)
|
self._reset_sequences(db_name)
|
||||||
|
|
||||||
if hasattr(self, 'fixtures'):
|
if self.fixtures:
|
||||||
# We have to use this slightly awkward syntax due to the fact
|
# We have to use this slightly awkward syntax due to the fact
|
||||||
# that we're using *args and **kwargs together.
|
# that we're using *args and **kwargs together.
|
||||||
call_command('loaddata', *self.fixtures,
|
call_command('loaddata', *self.fixtures,
|
||||||
|
@ -838,7 +841,7 @@ class TestCase(TransactionTestCase):
|
||||||
disable_transaction_methods()
|
disable_transaction_methods()
|
||||||
|
|
||||||
for db_name in self._databases_names(include_mirrors=False):
|
for db_name in self._databases_names(include_mirrors=False):
|
||||||
if hasattr(self, 'fixtures'):
|
if self.fixtures:
|
||||||
try:
|
try:
|
||||||
call_command('loaddata', *self.fixtures,
|
call_command('loaddata', *self.fixtures,
|
||||||
**{
|
**{
|
||||||
|
|
|
@ -24,6 +24,17 @@ class TestCaseFixtureLoadingTests(TestCase):
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class SubclassTestCaseFixtureLoadingTests(TestCaseFixtureLoadingTests):
|
||||||
|
"""
|
||||||
|
Make sure that subclasses can remove fixtures from parent class (#21089).
|
||||||
|
"""
|
||||||
|
fixtures = []
|
||||||
|
|
||||||
|
def testClassFixtures(self):
|
||||||
|
"Check that there were no fixture objects installed"
|
||||||
|
self.assertEqual(Article.objects.count(), 0)
|
||||||
|
|
||||||
|
|
||||||
class DumpDataAssertMixin(object):
|
class DumpDataAssertMixin(object):
|
||||||
|
|
||||||
def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
|
def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
|
||||||
|
|
Loading…
Reference in New Issue