问题描述
到目前为止,我遇到的所有代码示例都在类或方法内部使用了修补程序。所以我在嘲笑一个类,但我不想在每个测试函数中创建该类实例。我们可以做到吗?
到目前为止我所做的
from somefile import ClassA
def mock_init(self):
# something
@pytest.fixture(autouse=True)
def mock_setup(monkeypatch):
monkeypatch.setattr('ClassA.__init__',mock_init)
def test_something():
obj = ClassA()
# test codes
def test_another():
obj = classA()
# test codes
这有效。但是我想摆脱创建ClassA对象(全局创建ClassA对象并在每个测试函数中使用)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)