How to override a pytest fixture calling the original in pytest 4

后端 未结 2 1876
無奈伤痛
無奈伤痛 2021-02-10 02:59

I am defining a pytest fixture that to overrides the django_db_setup fixture.

The change I have sets up additional teardown for safety, as there are integration tests th

2条回答
  •  轮回少年
    2021-02-10 03:35

    To inject custom behavior before the initial fixture is called you can create separate fixture with this behavior and use it before the initial fixture in parameter list of fixture that overrides previously defined:

    @pytest.fixture(scope='session')
    def inject_before():
        print('inject_before')
    
    @pytest.fixture(scope='session')
    def django_db_setup(inject_before, django_db_setup):
        print('inject_after')
    

提交回复
热议问题