Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django/core/management/commands/loaddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def find_fixtures(self, fixture_label):
fixture_name = os.path.basename(fixture_name)
else:
fixture_dirs = self.fixture_dirs
if os.path.sep in fixture_name:
if os.path.sep in os.path.normpath(fixture_name):
fixture_dirs = [os.path.join(dir_, os.path.dirname(fixture_name))
for dir_ in fixture_dirs]
fixture_name = os.path.basename(fixture_name)
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures_regress/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@
_cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))


class TestLoadFixtureFromOtherAppDirectory(TestCase):
"""
This test should only fail on Windows when specifying a fixture in a
directory outside of the current app module. The fixture loader checks
the `fixture_name` for os.path.sep, which on Windows is `\`.

When specifying a path with forward slashes, the fixture will not be loaded,
as the path separator doesn't exist. The other unit tests for fixture
loading pass because they use os.path.join, not a hard-coded path, so
os.path.sep matches.
"""

fixtures = ['fixtures_regress/fixtures/absolute.json']

def test_fixtures_loaded(self):
absolute_count = Absolute.objects.count()
self.assertGreater(absolute_count, 0, "Absolute models not loaded from "
"fixtures.")


class TestFixtures(TestCase):

def animal_pre_save_check(self, signal, sender, instance, **kwargs):
Expand Down