2024-09-29 23:26:53 发布
网友
在独立的pytest测试用例中,我希望使用unittest.TestCase.assertNotIn(和^{}s other asserts)这样的断言,而不依赖于uniittest模块。使用python-assert这样的库是最佳实践吗?在
pytest
unittest.TestCase.assertNotIn
uniittest
最佳实践是使用语言assert语句,它产生不必要的unittest的{}方法。比较
assert
unittest
self.assertNotIn(a, b, 'element a is not found in sequence b')
与
后者更像Python。它也是docs中pytest名称的关键特性之一:
Detailed info on failing assert statements (no need to remember self.assert* names)
self.assert*
如果您缺少任何unittest方法,pytest旨在为它们提供替换:
with self.assertRaises(Exception): spam()
变成
with pytest.raises(Exception): spam()
你说
self.assertAlmostEqual(a, b)
assert a == pytest.approx(b)
等等
最佳实践是使用语言}方法。比较
assert
语句,它产生不必要的unittest
的{与
^{pr2}$后者更像Python。它也是docs中
pytest
名称的关键特性之一:如果您缺少任何
unittest
方法,pytest
旨在为它们提供替换:变成
你说
变成
等等
相关问题 更多 >
编程相关推荐