我有以下代码:pkg1/mock_class.py:class A: def ma(self): print(' class_A')class B: def __init__(self): self.var = 'vvv' def mb(self): a = A() print('class_B') a.ma()和测试代码:from unittest import mockimport pytestfrom pkg1.mock_class import B@pytest.fixture(scope='class')def mockA(): with mock.patch('pkg1.mock_class.A'): yieldclass TestB: def test_b(self, mockA): b = B() b.mb()我想使用fixture模拟整个A类(),并且我希望能够在将来使用参数化配置一些返回值。基本 - 只是像上面实现的模拟/修补不是工作类 B 被模拟,我不明白为什么。谢谢你的建议。
添加回答
举报
0/150
提交
取消