繁体   English   中英

Nosetests在未指定文件时失败

[英]Nosetests failing when no file is specified

我正在测试一些python代码,当我使用指定的文件运行鼻子测试时,一切都很好,但是当我想运行文件夹中的所有东西时,某些测试(大多数)失败了。

我使用的模拟,单元测试和鼻子与Python 2.7

谢谢

例如:

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

很抱歉,如果它是不足够的描述。

您实际上并没有像实际代码那样嘲笑os.path.exists 请尝试以下操作:

@mock.patch('os.path.exists')
def test_vm_exists(self, mock_exists):
    mock_exists.return_value = True
    fake_path = 'fake/path'

    response = self._VixConnection.vm_exists(fake_path)

    mock_exists.assert_called_with(fake_path)
    self.assertEqual(response, True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM