- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行 Django 1.7。我的项目文件树是这样的:
/project/app/fixtures/initial_data.json
/project/app/settings.py
manage.py loaddata app/fixtures/initial_data.json
将用于填充我的数据库的命令,但我想在
python manage.py migrate
时自动加载它正在运行。我的设置包括:
FIXTURE_DIRS = (
os.path.join(BASE_DIR, '/app/fixtures/'),
)
最佳答案
恐怕不是,这不是您的问题,因为自 Django 1.7 以来已弃用:
READ HERE
Automatically loading initial data fixtures¶
Deprecated since version 1.7: If an application uses migrations, there is no automatic loading of fixtures. Since migrations will be required for applications in Django 1.9, this behavior is considered deprecated. If you want to load initial data for an app, consider doing it in a data migration.
If you create a fixture named initial_data.[xml/yaml/json], that fixture will be loaded every time you run migrate. This is extremely convenient, but be careful: remember that the data will be refreshed every time you run migrate. So don’t use initial_data for data you’ll want to edit.
manage.py
,
# import execute_from_command_line
from django.core.management import execute_from_command_line
# add these lines for loading data
if len(sys.argv) == 2 and sys.argv[1] == 'migrate':
execute_from_command_line(['manage.py', 'loaddata'])
execute_from_command_line(sys.argv)
关于python - 自动加载 Django Fixture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27808486/
我正面临 pytest 固定装置的一个小问题,感谢您的帮助。 我有一些功能装置,如下所述。为简单起见,我没有展示实现。 @pytest.fixture() def get_driver():
我有一个现有的 pytest使用一些预定义列表来测试它们的交叉产品的测试: A_ITEMS = [1, 2, 3] B_ITEMS = [4, 5, 6] C_ITEMS = [7, 8, 9] 我还
我要传一个pytest.fixture函数到另一个 fixture 函数的 param 参数。像这样的东西: @pytest.fixture() def foo(): return "foo"
我试图避免在我的测试中重复太多的样板文件,我想以更有条理的方式重写它们。假设我有两个不同的解析器,它们都可以将文本解析为 doc。然后该文档将用于其他测试。最终目标是公开一个可以在其他测试中使用的 d
我有很多通过 pytest 管理的参数化装置。 有时,我希望使用 fixture 的测试不必担心应用参数。 是否可以制作一个参数化另一个 fixture 的 fixture ? import pyte
我有一对 fixture 用于测试具有 x-y 输入的函数。一个生成 x 值,另一个生成 y 值。测试取决于两者。 y 值也取决于 x 值。以下是设置摘要: import pytest @pytest
例子: from pytest import fixture, skip @fixture(params=['a', 'b']) def f1(request): yield request.
我的 Karma 配置文件中的文件属性是 files: [ // Program files 'public/js/init.js',
Conftest.py @pytest.fixture(scope="module") def fixture2(request): do something @pytest.fixture(
我正在使用 unittest.mock 模拟一个 API。我的界面是一个在后台使用 requests 的类。所以我正在做这样的事情: @pytest.fixture def mocked_api_an
基于此堆栈溢出:pytest fixture of fixtures 我在同一个文件中有以下代码: @pytest.fixture def form_data(): return { ...
命令行 python3 -m pytest src/spec/ --app=android conftest.py import pytest def pytest_addoption(parser)
我正在对我的代码进行一些测试,我得到了我的第一个“停止”,因为我不知道如何继续前进。在我加载灯具的 setUp() 函数中看到: public function setUp() { stati
我在两种模式下运行测试:裸 pytest 和 pytest-xdist。我有一个用模块范围定义的重型 fixture 。在这个 fixture 中,我对使用 xdist 运行测试的情况进行了一些优化:
我想在相同参数化测试的不同实例化之间共享 fixture,其中 fixture 本身也被参数化: #!/usr/bin/py.test -sv import pytest numbers_for_fi
我有一个包含多个 JSON 文件的 AWS S3 目录,这些文件用作测试输入。 我创建了一个 PyTest 模块,它使用模块范围的 fixture 下载所有 JSON 文件一次,然后运行多个测试函数
我有一个固定装置,它返回该端点名称(传入)的端点 名称是测试中设置的字符串。我在测试中每次调用端点(参数化)都搞砸了,现在我不知道如何在不每次调用端点的情况下获得相同的功能。 基本上,我只需要调用一次
如果我有两个参数化的 fixture ,我如何创建一个测试函数,首先用一个 fixture 的实例调用,然后用另一个 fixture 的实例调用? 我想创建一个以某种方式连接两个现有装置的新装置是有意
我是python的新手。我已经声明了一个装置 configure_loggers()范围为“ session ”。现在,我想在另一个 fixture 之前使用这个 fixture setup_app(
我想在另一个固定文件中实例化的固定文件中使用一个对象。类似于以下内容(不起作用): monitor_france: objecttype_id: 2 name1: i-france-1 n
我是一名优秀的程序员,十分优秀!