【发布时间】:2015-07-17 15:21:40
【问题描述】:
我有一个测试模块有一个自动使用装置
import pytest
@pytest.fixture(autouse=True):
def set_env_config(monkeypatch):
palladium_config = os.path.join(os.path.dirname(os.path.dirname(os.getcwd())), 'config.py')
monkeypatch.setenv('PALLADIUM_CONFIG', palladium_config)
from A import B
并且在此测试模块中的每个后续测试中都需要 B 类,但是对于任何测试都无法实现此导入。
另外,我只修补环境变量
@pytest.fixture(autouse=True):
def set_env_config(monkeypatch):
palladium_config = os.path.join(os.path.dirname(os.path.dirname(os.getcwd())), 'config.py')
monkeypatch.setenv('PALLADIUM_CONFIG', palladium_config)
并在每个测试用例中导入B类,它成功了。
这是为什么呢?为什么我不能在 autouse 夹具中导入类
非常感谢
【问题讨论】:
-
您看到了什么错误或堆栈跟踪(如果有)?