[英]pytest-django run with migrations ignores database triggers
My Django app depends on a database with some triggers setup. 我的Django应用程序依赖于具有某些触发器设置的数据库。 I use this part of the documentation to set up the triggers in the test database for the pytest runner.
我使用文档的这一部分在pytest运行程序的测试数据库中设置触发器。
@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker):
with django_db_blocker.unblock():
cur = connection.cursor()
cur.execute([...]) # Set it up
I run my tests with --nomigrations
and it works as expected. 我使用
--nomigrations
运行测试,它可以按预期运行。 Without --nomigrations
(test runs migrations first), the triggers are not working. 如果没有
--nomigrations
(测试首先运行迁移),则触发器不起作用。
So trying to debug this, I've confirmed 因此,我尝试调试
psql test_<mydb>
and looking in the pg_trigger
table) psql test_<mydb>
并在寻找pg_trigger
表) Let me just stress once more that the tests pass when run without migrations and testing the functionality when running the dev server against my dev db I can also confirm that it works 让我再次强调一下, 在不进行迁移的情况下运行时测试通过了,在对我的dev db运行dev服务器时测试了功能,我也可以确认它是否有效
So, my question is: Is there any reason that running with migrations should do things differently? 因此,我的问题是:使用迁移进行操作应该有什么不同的理由吗? Or is it likely that my migrations do something obscure which makes things fail, ie it is my own fault?
还是我的迁移所做的事情晦涩难懂,导致事情失败,即是我自己的错?
Placing trigger in django_db_setup
worked for me 将触发器放在
django_db_setup
对我django_db_setup
@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker):
with django_db_blocker.unblock():
cur = connection.cursor()
cur.execute('''CREATE TRIGGER search_vector_update BEFORE INSERT OR UPDATE
ON xml_templates_template FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(search_vector, 'pg_catalog.english', name, description, info);
''')
pytest (4.4.1) is run with --nomigrations
pytest(4.4.1)使用
--nomigrations
运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.