【发布时间】: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