Opened 13 years ago

Closed 5 years ago

#16713 closed Bug (invalid)

Fixture loading for tests ignore database specific names.

Reported by: brent@… Owned by: nobody
Component: Testing framework Version: 1.3
Severity: Normal Keywords: fixtures, multidb
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is either a doc clarification bug, or a real bug. But based on this from the documentation:

Database-specific fixtures
If you are in a multi-database setup, you may have fixture data that you want to load onto one database, but not onto another. In this situation, you can add database identifier into . If your DATABASES setting has a ‘master’ database defined, you can define the fixture mydata.master.json or mydata.master.json.gz. This fixture will only be loaded if you have specified that you want to load data onto the master database.

This does not working during testing though. If you do not set multi_db = True, the fixtures are loaded into 'default' only. If you do set multi_db = True, all fixtures are loaded into all databases. There is no way to load some data into one database and some other data into the second as the above paragraph states.

If this is *really* a bug and just not the expected behavior and/or someone wants the expected behavior to change I could submit a patch. But I don't want to fix something that may not be broken.

Attached is a test project that shows the behavior.

Attachments (1)

fixturetest.tar.gz (19.1 KB ) - added by brent@… 13 years ago.
Test Project that show Fixture loading problems

Download all attachments as: .zip

Change History (4)

by brent@…, 13 years ago

Attachment: fixturetest.tar.gz added

Test Project that show Fixture loading problems

comment:1 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

This test shows how this feature works: https://code.djangoproject.com/browser/django/trunk/tests/regressiontests/multiple_database/tests.py#L1621

With the following changes, your tests pass:

--- testapp/tests.py.orig	2011-08-28 12:11:44.000000000 +0200
+++ testapp/tests.py	2011-08-28 12:11:02.000000000 +0200
@@ -12,7 +12,7 @@
     """
     multi_db = True
 
-    fixtures = ['people.default.json']
+    fixtures = ['people']
 
     def test_fixtures_loaded_to_default(self):
         """
@@ -35,7 +35,7 @@
     This should load the one into default only.
     """
 
-    fixtures = ['people.default.json']
+    fixtures = ['people']
 
     def test_fixtures_loaded_to_default(self):
         """
@@ -61,7 +61,7 @@
     """
     multi_db = True
 
-    fixtures = ['people.default.json', 'morepeople.core.json']
+    fixtures = ['people', 'morepeople']
 
     def test_fixtures_loaded_to_default(self):
         """

I think it's a bug. The docs say it's possible to pass only the "base name" of the fixture and let Django figure out the rest (database, format, compression); they don't say it's mandatory.

comment:2 by anonymous, 10 years ago

Any hope of seeing this bug fixed?

comment:3 by Mariusz Felisiak, 5 years ago

Resolution: invalid
Status: newclosed
Summary: Fixture loading for tests ignore database specific namesFixture loading for tests ignore database specific names.

multi_db will be removed in Django 3.1 (see b61ea56789a5825bd2961a335cb82f65e09f1614). Despite the fact that behavior described in this ticket is still valid when using TestCase.databases it is also documented in TransactionTestCase.databases and TransactionTestCase.fixtures, e.g.:

By default, fixtures are only loaded into the default database. If you are using multiple databases and set TransactionTestCase.databases, fixtures will be loaded into all specified databases.

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