假设我有下一个测试结构:
test/ module1/ test1.py module2/ test2.py module3/ test3.py
我如何设置某些方法在所有这些测试之前只调用一次?
最佳答案
您可以使用自动装置:
# content of test/conftest.py
import pytest
@pytest.fixture(scope="session", autouse=True)
def execute_before_any_test():
# your setup code goes here, executed ahead of first test
参见 pytest fixture docs获取更多信息。
关于python - 几个模块的 Pytest init 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19225279/