Opened 10 years ago
Closed 10 years ago
#23612 closed Bug (fixed)
Relative fixture paths not working on Windows 8.1
Reported by: | Brandon Taylor | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | windows fixtures |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I have a Django 1.6.6 project that is not loading fixtures from relative paths using Python 2.7.8 on Windows 8.1. Works just fine in Linux.
Example Test Case:
# cart/tests.py class CartTestBase(TestCase): fixtures = ['products/fixtures/product_categories.json', 'products/fixtures/brands.json', 'products/fixtures/products.json']
Which fits into a directory structure of:
ecomm_app/ cart/ __init__.py models.py tests.py . . . products/ fixtures/ products/fixtures/product_categories.json products/fixtures/brands.json products/fixtures/products.json __init__.py models.py . . .
The specific error message is:
UserWarning: No fixture named 'products/fixtures/products' found. warnings.warn("No fixture named '%s' found." % fixture_name)
The corresponding app modules are listed in INSTALLED_APPS
and work fine otherwise. Specifying an absolute path does work, but obviously isn't cross-platform. Specifying a root-relative path does not work, e.g.: /products/fixtures/brands.json
Moving the fixtures to /cart/fixtures/
and referencing them by name only works.
Change History (13)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
That is correct. I took a look at the directories returned by fixture_dirs()
in core/management/loaddata.py
and the paths are correct, but it doesn't seem to be concatenating the paths correctly if I specify a directory structure plus the file name.
The paths returned by fixture_dirs()
are in: C:\\path\\path\\path
format.
Leaving the directory structure off entirely works as it picks up the products/fixtures/
directory, but you'd most likely run into issues if there were fixtures with duplicate names.
comment:3 by , 10 years ago
I think the problem is with line 189 in loaddata.py. It's checking for os.path.sep
which on Windows is \
. Aren't we always supposed to use forward slashes /
with Python on Windows? Changing os.path.sep
to /
allows the relative paths to work.
comment:4 by , 10 years ago
How about changing line 189 to:
if os.path.sep in os.path.normpath(fixture_name):
That way it is still based on the path separator for the os. Paths to fixtures can still be written using /
so they are consistent with other paths in Django like template and static file directories, where the documentation specifically states to use forward slashes.
comment:5 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.7 → master |
comment:6 by , 10 years ago
I submitted a Pull Request with a fix: https://github.com/django/django/pull/3324
Running the test suite yields no failures.
comment:7 by , 10 years ago
Has patch: | set |
---|
comment:8 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:9 by , 10 years ago
The test introduced with this fix doesn't pass. Created a separate ticket #23633
comment:10 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
I think we should try to make this test work when running tests via ./tests/runtests.py
since all the other tests work and we have made similar efforts to fix tests that didn't (e.g. d11e83620380fdd98679b09062eefd25f0a98e21).
comment:13 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
First I assume the files in
products/fixtures/
are named<name>.json
and notproducts/fixtures/<name>.json
.I don't have Windows VM at hand but isn't it using backslashes (
\
) as directory separators?