【发布时间】:2013-12-08 10:16:35
【问题描述】:
我正在测试一些 python 代码,当我使用指定的文件运行 nosetests 时,一切都很好,但是当我想运行文件夹中的所有内容时,一些测试(大多数)失败。
我在 python 2.7 中使用 mock、unittest 和 nose
谢谢
例如:
AssertionError: Expected call: mock('fake/path')
Not called
在这个测试中
def test_vm_exists(self):
fake_path = 'fake/path'
os.path.exists = mock.MagicMock()
os.path.exists.return_value = True
response = self._VixConnection.vm_exists(fake_path)
os.path.exists.assert_called_with(fake_path)
self.assertEqual(response, True)
这是回购: https://github.com/trobert2/nova-vix-driver/tree/unittests/vix/tests
如果描述性不够,请见谅。
【问题讨论】:
-
欢迎来到stackoverflow。你能显示一些代码吗?什么失败,哪个异常,...请改进您的问题。
-
我进行了编辑。感谢您的意见
-
非常感谢!打补丁解决一切。当我使用 MagicMock 时,我认为它只能在测试范围内工作。我错了,谢谢。
标签: python unit-testing mocking nose