From 2e48cf6bd9499f888a6cebf9f18c92717f1df55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Sat, 9 May 2020 19:37:44 +0200 Subject: [PATCH] Fixed fixtures loading isolation in tests. fixture1.json and fixture2.json exist in both "fixtures" and "fixtures_model_package". Both apps are listed in "INSTALLED_APPS". The loaddata management command loads from installed apps, thus loads both fixtures when a test runs loaddata with any of these fixtures. --- .../fixtures/{fixture1.json => model_package_fixture1.json} | 0 .../fixtures/{fixture2.json => model_package_fixture2.json} | 0 tests/fixtures_model_package/tests.py | 6 +++--- 3 files changed, 3 insertions(+), 3 deletions(-) rename tests/fixtures_model_package/fixtures/{fixture1.json => model_package_fixture1.json} (100%) rename tests/fixtures_model_package/fixtures/{fixture2.json => model_package_fixture2.json} (100%) diff --git a/tests/fixtures_model_package/fixtures/fixture1.json b/tests/fixtures_model_package/fixtures/model_package_fixture1.json similarity index 100% rename from tests/fixtures_model_package/fixtures/fixture1.json rename to tests/fixtures_model_package/fixtures/model_package_fixture1.json diff --git a/tests/fixtures_model_package/fixtures/fixture2.json b/tests/fixtures_model_package/fixtures/model_package_fixture2.json similarity index 100% rename from tests/fixtures_model_package/fixtures/fixture2.json rename to tests/fixtures_model_package/fixtures/model_package_fixture2.json diff --git a/tests/fixtures_model_package/tests.py b/tests/fixtures_model_package/tests.py index 78afed1b90..8e0c40f471 100644 --- a/tests/fixtures_model_package/tests.py +++ b/tests/fixtures_model_package/tests.py @@ -6,7 +6,7 @@ from .models import Article class SampleTestCase(TestCase): - fixtures = ['fixture1.json', 'fixture2.json'] + fixtures = ['model_package_fixture1.json', 'model_package_fixture2.json'] def test_class_fixtures(self): "Test cases can load fixture objects into models defined in packages" @@ -25,7 +25,7 @@ class FixtureTestCase(TestCase): def test_loaddata(self): "Fixtures can load data into models defined in packages" # Load fixture 1. Single JSON file, with two objects - management.call_command("loaddata", "fixture1.json", verbosity=0) + management.call_command('loaddata', 'model_package_fixture1.json', verbosity=0) self.assertQuerysetEqual( Article.objects.all(), [ "Time to reform copyright", @@ -36,7 +36,7 @@ class FixtureTestCase(TestCase): # Load fixture 2. JSON file imported by default. Overwrites some # existing objects - management.call_command("loaddata", "fixture2.json", verbosity=0) + management.call_command('loaddata', 'model_package_fixture2.json', verbosity=0) self.assertQuerysetEqual( Article.objects.all(), [ "Django conquers world!",