Search code examples
djangodjango-fixtures

Relative fixture paths in Django not working on Windows


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

What's going on with these fixtures?


Solution

  • So, the problem was that the path to the fixtures was not being normalized correctly in Windows. I submitted a pull request that was accepted, so this will hopefully go out in the next version of Django after 1.7.1