使用迁移运行pytest django会忽略数据库触发器
我的Django应用程序依赖于带有一些触发器设置的数据库。我用于在测试数据库中为pytest runner设置触发器使用迁移运行pytest django会忽略数据库触发器,django,postgresql,pytest,database-trigger,pytest-django,Django,Postgresql,Pytest,Database Trigger,Pytest Django,我的Django应用程序依赖于带有一些触发器设置的数据库。我用于在测试数据库中为pytest runner设置触发器 @pytest.fixture(scope='session') def django_db_setup(django_db_setup, django_db_blocker): with django_db_blocker.unblock(): cur = connection.cursor() cur.execute([...]) #
@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
我使用--nomigrations
运行我的测试,它按预期工作。如果没有--nomigration
(首先测试运行迁移),触发器将无法工作
试着调试这个,我已经确认了
psql test\uu
并查看pg\u trigger
表)所以,我的问题是:是否有任何理由认为运行迁移应该以不同的方式进行?还是我的迁移可能会做一些模糊的事情,导致失败,即这是我自己的错?将触发器置于django\u db\u设置中对我来说很有效
@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)运行时带有
--nomigrations
任何不使用django测试框架的原因?@e4c5太慢了。pytest库的许多额外好处