pytest 参数化测试是否适用于基于单元测试类的测试? [英] Does pytest parametrized test work with unittest class based tests?
本文介绍了pytest 参数化测试是否适用于基于单元测试类的测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试将参数化的 @pytest.mark.parametrize
测试添加到基于类的单元测试中.
I've been trying to add parametrized @pytest.mark.parametrize
tests to a class based unittest.
class SomethingTests(unittest.TestCase):
@pytest.mark.parametrize(('one', 'two'), [
(1, 2), (2, 3)])
def test_default_values(self, one, two):
assert one == (two + 1)
但是参数化的东西没有发挥作用:
But the parametrized stuff didn't kick in:
TypeError: test_default_values() takes exactly 3 arguments (1 given)
我已经切换到简单的基于类的测试(没有单元测试).但我想知道是否有人尝试过并且有效.
I've switched to simple class based tests (without unittest). But I'd like to know if anyone tried it and it worked.
推荐答案
根据 pytest 文档:
unittest.TestCase 方法不能直接接收fixture函数作为实施的论点可能会影响运行常规的unittest.TestCase 测试套件.
unittest.TestCase methods cannot directly receive fixture function arguments as implementing that is likely to inflict on the ability to run general unittest.TestCase test suites.
这篇关于pytest 参数化测试是否适用于基于单元测试类的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文