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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23612>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0
Old description:
New description:
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:
{{{#!python
# cart/tests.py
--
Comment:
First I assume the files in `products/fixtures/` are named `<name>.json`
and not `products/fixtures/<name>.json`.
I don't have Windows VM at hand but isn't it using backslashes (`\`) as
directory separators?
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:1>
Comment (by alsoicode):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:2>
Comment (by alsoicode):
I think the problem is with line 183 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:3>
Comment (by alsoicode):
How about changing line 183 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:4>
* version: 1.7 => master
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:5>
Comment (by alsoicode):
I submitted a Pull Request with a fix:
https://github.com/django/django/pull/3324
Running the test suite yields no failures.
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:6>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:7>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"16ed35fafc0583b485a0289afda632f8261ecc96"]:
{{{
#!CommitTicketReference repository=""
revision="16ed35fafc0583b485a0289afda632f8261ecc96"
Fixed #23612 -- Normalized fixuture paths to allow referencing relative
paths on Windows.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:8>
Comment (by jaap3):
The test introduced with this fix doesn't pass. Created a separate ticket
#23633
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:9>
* status: closed => new
* resolution: fixed =>
Comment:
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).
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:10>
Comment (by timgraham):
Here's a [https://github.com/django/django/pull/3406 PR] to allow the
above.
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:11>
Comment (by Tim Graham <timograham@…>):
In [changeset:"28da093ae24c3fb9070055df5d727a9c51c9cf83"]:
{{{
#!CommitTicketReference repository=""
revision="28da093ae24c3fb9070055df5d727a9c51c9cf83"
Allowed test from refs #23612 to be run from a directory other than tests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:12>
* status: new => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/23612#comment:13>