Python @ddt与py.test一起工作吗?
@ddt是与py.test一起工作还是必须使用unittest格式? 我有一个测试,其中安装夹具位于conftest.py文件中。当我运行测试时,它出错了,因为它没有运行安装夹具。例如:Python @ddt与py.test一起工作吗?,python,selenium,pytest,ddt,Python,Selenium,Pytest,Ddt,@ddt是与py.test一起工作还是必须使用unittest格式? 我有一个测试,其中安装夹具位于conftest.py文件中。当我运行测试时,它出错了,因为它没有运行安装夹具。例如: @ddt class Test_searchProd: @data(['clothes': 3],['shoes': 4]) @unpack def test_searchAllProduct(setup,productType): ..... 基本上,设置夹具是打开一个特定的URL。
@ddt
class Test_searchProd:
@data(['clothes': 3],['shoes': 4])
@unpack
def test_searchAllProduct(setup,productType):
.....
基本上,设置夹具是打开一个特定的URL。。。
我是否做了一些不正确的事情,或者@ddt不能与py.test一起使用?意味着要由TestCase
子类使用,因此它不适用于裸测试类。但是请注意,pytest可以运行使用ddt
的TestCase
子类,因此,如果您已经有了基于ddt的测试套件,那么它应该使用pytest运行程序运行,而无需修改
还要注意的是,pytest有,它可以用来替换ddt
支持的许多用例
例如,以下基于滴滴涕的测试:
@ddt
class FooTestCase(unittest.TestCase):
@data(1, -3, 2, 0)
def test_not_larger_than_two(self, value):
self.assertFalse(larger_than_two(value))
@data(annotated(2, 1), annotated(10, 5))
def test_greater(self, value):
a, b = value
self.assertGreater(a, b)
进入pytest:
class FooTest:
@pytest.mark.parametrize('value', (1, -3, 2, 0))
def test_not_larger_than_two(self, value):
assert not larger_than_two(value)
@pytest.mark.parametrize('a, b', [(2, 1), (10, 5)])
def test_greater(self, a, b):
assert a > b
或者,如果您愿意,您甚至可以完全取消该课程:
@pytest.mark.parametrize('value', (1, -3, 2, 0))
def test_not_larger_than_two(value):
assert not larger_than_two(value)
@pytest.mark.parametrize('a, b', [(2, 1), (10, 5)])
def test_greater(a, b):
assert a > b
明亮的完全忘记了参数化功能。谢谢我甚至都不知道,谢谢你把我从滴滴涕的枷锁中解放出来。