Code

Opened 3 years ago

Last modified 3 years ago

#16713 new Bug

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@… 3 years ago.
Test Project that show Fixture loading problems

Download all attachments as: .zip

Change History (2)

Changed 3 years ago by brent@…

Test Project that show Fixture loading problems

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.