Fixed #33949 -- Fixed fixture dirs duplicates with Path instances.

This commit is contained in:
Claude Paroz 2022-08-23 12:05:27 +02:00 committed by Carlton Gibson
parent 7e6b537f5b
commit 903ac2f364
2 changed files with 15 additions and 1 deletions

View File

@ -367,7 +367,7 @@ class Command(BaseCommand):
for app_config in apps.get_app_configs():
app_label = app_config.label
app_dir = os.path.join(app_config.path, "fixtures")
if app_dir in fixture_dirs:
if app_dir in [str(d) for d in fixture_dirs]:
raise ImproperlyConfigured(
"'%s' is a default fixture directory for the '%s' app "
"and cannot be listed in settings.FIXTURE_DIRS."

View File

@ -569,6 +569,20 @@ class TestFixtures(TestCase):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
management.call_command("loaddata", "absolute.json", verbosity=0)
@override_settings(FIXTURE_DIRS=[Path(_cur_dir) / "fixtures"])
def test_fixture_dirs_with_default_fixture_path_as_pathlib(self):
"""
settings.FIXTURE_DIRS cannot contain a default fixtures directory
for application (app/fixtures) in order to avoid repeated fixture loading.
"""
msg = (
"'%s' is a default fixture directory for the '%s' app "
"and cannot be listed in settings.FIXTURE_DIRS."
% (os.path.join(_cur_dir, "fixtures"), "fixtures_regress")
)
with self.assertRaisesMessage(ImproperlyConfigured, msg):
management.call_command("loaddata", "absolute.json", verbosity=0)
@override_settings(
FIXTURE_DIRS=[
os.path.join(_cur_dir, "fixtures_1"),