Questions tagged «magicmock»

1
Python返回MagicMock对象而不是return_value
我有一个Python文件a.py包含两个类A和B。 class A(object): def method_a(self): return "Class A method a" class B(object): def method_b(self): a = A() print a.method_a() 我想通过嘲笑method_b在课堂上B进行单元测试A。这是testa.py用于此目的的文件内容: import unittest import mock import a class TestB(unittest.TestCase): @mock.patch('a.A') def test_method_b(self, mock_a): mock_a.method_a.return_value = 'Mocked A' b = a.B() b.method_b() if __name__ == '__main__': unittest.main() 我希望得到Mocked A输出。但是我得到的是: <MagicMock name='A().method_a()' id='4326621392'> …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.