Pytest框架
王小彩
这个作者很懒,什么都没留下…
展开
-
allure安装
下载allureallure是一个通用的测试报告框架下载地址:http://allure.qatools.ru/安装allure将解压后的文件放在指定路径下,并将该路径下的bin目录添加至系统环境变量path中验证:在pycharm中下载allure插件pip install allure-pytest....原创 2020-08-21 16:17:46 · 431 阅读 · 0 评论 -
Pytest框架【6】:fixture--conftest.py
说明: conftest.py配置里可以实现数据共享,不需要import就能自动找到配置内容。注意以下3点:1、conftest.py配置脚本名称是固定的,不能修改名称2、conftest.py与运行的用例要在同一个package下,并且有__init__.py文件3、不需要import导入conftest.py,pytest用例会自动查找语法: fixture(scope=“function”, params=None, autouse=False, ids=None, name=None):原创 2020-06-02 11:05:18 · 333 阅读 · 0 评论 -
Pytest框架【5】:setup和teardown
setup和teardown在每次用例开始前和结束后都会执行一次。setupClass和teardownClass,需配合@classmethod装饰器一起使用,启动一次可以执行多个用例。pytest框架也有类似的setup和teardown。用例运行级别函数级(setup_function/teardown_function)只对函数用例生效,每个test都运行。类级别(setup_class/teardown_class)只在类的前后运行一次,每个class中的所有test只运行一次。模块原创 2020-05-29 16:26:22 · 458 阅读 · 0 评论 -
Pytest框架【4】:pytest命令行
命令行参数1、-v:用于显示每个测试函数的执行结果2、-q:只显示整体测试结果3、-s:用于显示测试函数中print()函数输出4、-x:exitfirst,exit instantly on first error or failed test5、-h:帮助import pytest# test_demo.py@pytest.fixture(scope='function', autouse=True)def before(): print('\n--->before')原创 2020-05-29 14:53:03 · 545 阅读 · 0 评论 -
Pytest框架【3】:使用pycharm运行pytest
pycharm编写脚本文件import pytest@pytest.fixture(scope='function', autouse=True)def before(): print('\n--->before')class Test_ABC: def setup(self): print('\n--->setup') def test_a(self): print('\n--->test_a') as原创 2020-05-29 14:34:33 · 613 阅读 · 0 评论 -
Pytest框架【2】:用例规则
pytest用例编写规则:1、测试文件以 ‘test_’ 开头,以 ‘_test’ 结尾。2、测试类以 ‘Test’ 开头,并且不能带有 init 方法。3、测试函数以 ‘test_’ 开头。4、断言使用基本的assert。pytest Exit Code清单:Exit Code 0:所有用例执行完毕,全部通过。Exit Code 1:所有用例执行完毕,存在Failed的测试用例。Exit Code 2:用户中断测试执行。Exit Code 3:测试执行过程中发生了内部错误。Exit C原创 2020-05-29 10:35:28 · 362 阅读 · 0 评论 -
Pytest框架【1】:环境安装
安装:1、安装方法pip install -U pytest2、查看版本pip show pytest也可以pytest --versionpytest用例规则:1、测试文件以 ‘test_’ 开头,以 ‘_test’ 结尾。2、测试类以 ‘Test’ 开头,并且不能带有 init 方法。3、测试函数以 ‘test_’ 开头。4、断言使用基本的assert。pytest Exit Code清单:Exit Code 0:所有用例执行完毕,全部通过。Exit Cod原创 2020-05-29 09:47:21 · 234 阅读 · 2 评论