Opened 2 years ago

Last modified 2 years ago

#24680 new Cleanup/optimization

In testing, warnings appear when loading database-specific fixtures

Reported by: Zhongyuan Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Normal Keywords: testing, fixtures, database-specific, warning
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

How to reproduce

settings.py:

DATABASES = {
    'db1': {......},
    'db2': {......}
}

fixtures:
fixtures/data1.db1.json
fixtures/data2.db2.json

tests.py:

class FixtureTestCase(TestCase):
    fixtures = ['data1', 'data2']
    multi_db = True

    def test(self): pass

Expected results
As stated in the doc https://docs.djangoproject.com/en/dev/ref/django-admin/#database-specific-fixtures, "data1" should be loaded into "db1" DB, "data2" should be loaded into "db2".

Real results
Fixtures were loaded correctly. But there were warnings appeared: "UserWarning: No fixture named 'data1' found."; "UserWarning: No fixture named 'data2' found."

As everything was set up as required, warnings should not appear

How it happened
"TestCase._fixture_setup" call "loaddata" command on all database-fixture combinations, like this:

loaddata data1 data2 database=db1
loaddata data1 data2 database=db2

For "db1", "data2" is not found; and for "db2", "data1" is not found. So warnings raised.

I think the implementation of "_fixture_setup" and/or "loaddata" need some change, to make it work perfectly

Change History (1)

comment:1 Changed 2 years ago by Tim Graham

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