01.unittest运行方法:
1)代码中追加如下内容,然后直接运行:
if __name__ == '__main__': unittest.main()
2)在python的交互中执行以下内容:
import unittest test_dir = './' discover = unittest.defaultTestLoader.discover(test_dir, pattern='test.py') runner=unittest.TextTestRunner() runner.run(discover)
02.nosetest运行方法:
-w ,指定一个目录运行测试。目录可以是相对路径或绝对路径。
例如: nosetest -w c: est1,只运行目录c: est1下的测试。
可以指定多个目录,例如: nosetest -w c: est1 -w c: est2。
class TestCount(unittest.TestCase): @patch("function.multiply") def test_add_and_multiply(self,mock_multiply): x = 3 y = 5 mock_multiply.return_value = 15 addition, multiple = function.add_and_multiply(x, y) mock_multiply.assert_called_once_with(3, 5) self.assertEqual(8, addition) self.assertEqual(15, multiple)
03.问题对应:
问题来源:nova单元测试1)nosetest和
错误消息:RuntimeError: No 'nova.ipv6_backend' driver found, looking for 'rfc2462'
解决方法:tox -e cover xxx
解决参照:https://bugs.launchpad.net/nova/+bug/1448031