KaG*_*aGo 3 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):
.....
Run Code Online (Sandbox Code Playgroud)
基本上,设置夹具是打开一个特定的URL ...我做错了什么或者@ddt不适用于py.test?
ddt意在由TestCase子类使用,因此它不适用于裸测试类.但是请注意,pytest可以运行TestCase使用得很好的子类ddt,所以如果你已经有了一个基于ddt的测试套件,它应该在没有使用pytest runner的修改的情况下运行.
另请注意,pytest具有参数化,可用于替换支持的许多用例ddt.
例如,以下基于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)
Run Code Online (Sandbox Code Playgroud)
成为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
Run Code Online (Sandbox Code Playgroud)
或者如果你愿意,你甚至可以完全摆脱这个课程:
@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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1766 次 |
| 最近记录: |