Pytest:
1. 优点:
支持参数化;
测试用例skip、xfail自动失败重试;
可以用于selenium/appium等自动化测试,接口自动化测试(pytest+request)
测试报告:pytest+allure pytest+xdist
可以与jenkins进行集成
2. 文件命令:
测试类必须以Test*开头
测试用例必须以test_*.py 或者 *_test.py
测试类中不能包含__init__
3. 执行:
不能直接使用python x.py执行;需要使用pytest x.py执行
若要使用python执行,则需要:
If __name__==’__main__’:
pytest.main([‘test_a.py’])
pytest.main([‘test_a.py::TestDemo’,’-v’])
Pytest -k 指定用例 -v显示详情
4. 装饰器:@pytest.fixture()
作用类似于setup,某条用例需要使用,则在用例中调用,如
@pytest.fixture()
def login():
Return null
def test_a(self, login)
5. Pytest的参数化:
方式一:
@pytest.mark.parametrize((“a”,”b”),[(1,2),(3,4)])
方式二:
yaml
@pytest.mark.parametrize((“a”,”b”),yaml.safe_load(open(“./data.yaml”)))
yaml格式的书写:例如(a,b)
-
- 10
- 20
-
- 10
- 20
表示(10,20)(10,20)
数据驱动的作用:
测试步骤;测试数据;配置的数据;