随笔分类 - Pytest
摘要:遇见的问题 np.nan被strip之后仍为nan,但是此nan无法被.fillna()处理,处理后仍然为nan get_address_local_mail['CountryID_mail'] = get_address_local_mail['CountryID_mail'].apply(lam
阅读全文
摘要:@pytest.mark.parametrize(args_name,args_value) args_name:参数名称,用于将参数传递给函数 args_value:参数值(列表和字典列表,元组和字典元组),有n个值则用例执行n次。 传单个参数: class TestCompany(): @pyt
阅读全文
摘要:allure官网 https://github.com/allure-framework/allure2/releases 1. 安装allure-pytest插件 2.下载allure,下载之后解压,解压之后还要配置环境变量(环境变量path下加bin路径) 3.验证allure是否安装成功: d
阅读全文
摘要:使用Python自己的断言 assert 举例: assert flag is True assert 1 == 2
阅读全文
摘要:1-3优先级逐渐降低: 会话:fixture的session级别最高 class:fixture的class scope的优先级 > setup_class function: fixture的function scope的优先级 > setup_method
阅读全文
摘要:与全局配置pytest.ini配置文件结合使用(见配置文件章节) 例如 配置文件中设置 markers = #分成三类High/Normal,Low High: smoke test Normal: product test Low: full test cases 分模块执行: - Case中加装
阅读全文
摘要:安装 1. 安装Python 2. 安装pytest: pip install -U pytest 3. 安装常用插件 pip install -r requirement.txt PS: 常用插件: pytest allure-pytest requests PyYAML pandas openp
阅读全文
摘要:conftest.py文件专门用来存放fixture的文件,名称固定不能修改。 conftest.py中的所有方法在调用时都不需要导包 一个用例可以同时调用多个conftest.py中的多个方法 一般conftest.py中的方法autouse= True, 自动执行。 conftest.py放在最
阅读全文
摘要:使用fixture实现部分测试用例前后置,能支持多个参数,使用方式如下 @pytest.fixture(scope=”function”,autouse= False, params=loginutil(),ids=[0,1,2],name="login") 默认值,score = None, au
阅读全文
摘要:setup_method#每个用例之前 teardown_method #每个用例之后 setup_class#每个类之前 teardown_class #每个类之后
阅读全文
摘要:默认测试用例规则: 模块名必须以test_开头或者_test结尾(.py文件) 测试类必须以Test开头,并不能带有init方法(Class in .py一般是模块名首字母大写样式) 测试用例必须以test_开头。(def under Class) 执行:Alt+Enter自动导包。
阅读全文
摘要:1.无条件跳过用例 @pytest.mark.skip(reason="无理由跳过") 2.有条件跳过用例 @pytest.mark.skipif(workage<5,reason="无理由跳过") @pytest.mark.skipif(workage<5,reason="有理由跳过") def
阅读全文
摘要:通过全局配置pytest.ini文件执行() //会自动加载此文件 注意: 一般放在项目根目录下,并且名字必须为pytest.ini 编码格式为ANSI,有中文需要GBS1218 pytest.ini可以改变默认测试用例规则 不管main还是命令方式都会自动加载此配置文件 内容举例: [pytest
阅读全文
摘要:执行的参数 -vs -v 输出详细信息 -s输出调试信息(print(“xxx”)里的xxx)。 -n 多线程运行。(前提安装插件pytest-xdist),例如pytest -n=2 --returns num失败重跑(安装插件 pytest-returnfaires) 例 pytest -vs
阅读全文
摘要:通过命令行方式执行 pytest 执行所有用例或者 pytest xxx.py执行指定模块 命令 pytest
阅读全文
摘要:通过主函数main方式执行 运行所有case:pytest.main() 运行模块: pytest.main(['test_company.py','test_school.py']) 指定目录:pytest.main(['./testcases']) If __name__ == ‘__main_
阅读全文