【问题标题】:Relative fixture paths in Django not working on WindowsDjango 中的相对固定路径在 Windows 上不起作用
【发布时间】:2023-04-04 10:31:01
【问题描述】:

我有一个 Django 1.6.6 项目,它没有在 Windows 8.1 上使用 Python 2.7.8 从相对路径加载固定装置。在 Linux 中运行良好。

示例测试用例:

# cart/tests.py

class CartTestBase(TestCase):
    fixtures = ['products/fixtures/product_categories.json',
    'products/fixtures/brands.json', 'products/fixtures/products.json']

适合以下目录结构:

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
        . . .

具体报错信息为:

UserWarning: No fixture named 'products/fixtures/products' found.
warnings.warn("No fixture named '%s' found." % fixture_name)

相应的应用程序模块在INSTALLED_APPS 中列出,否则可以正常工作。指定绝对路径确实有效,但显然不是跨平台的。指定根相对路径不起作用,例如:/products/fixtures/brands.json

这些装置是怎么回事?

【问题讨论】:

  • 我不确定,但您可以尝试在测试中仅指定夹具名称,例如:fixtures = ['product_categories.json', 'brands.json', 'products.json']
  • 将固定装置移动到:/cart/fixtures 并将路径更改为仅文件名确实有效。听起来夹具加载器可能存在错误。
  • 我已经就这个问题开了一张票:code.djangoproject.com/ticket/23612#ticket

标签: django django-fixtures


【解决方案1】:

所以,问题是在 Windows 中,灯具的路径没有被正确规范化。我提交了一个被接受的拉取请求,所以这有望在 1.7.1 之后的下一个版本的 Django 中消失

【讨论】:

    猜你喜欢
    • 2015-08-18
    • 2018-10-10
    • 1970-01-01
    • 2017-07-12
    • 2014-07-11
    • 2013-10-22
    • 1970-01-01
    • 2011-07-19
    • 2013-06-30
    相关资源
    最近更新 更多