摘要: pytest-配置文件 conftest.py 如果希望多个测试文件共享fixture,可以在公共目录下新建一个conftest.py文件,将fixture放在其中 例: 目录结构: . ├── conftest.py ├── __init__.py ├── test_001.py └── test 阅读全文
posted @ 2020-07-20 22:41 静心&得意 阅读(1013) 评论(0) 推荐(0) 编辑
摘要: pytest-fixture fixture是在测试函数运行前后,由pytest执行的外壳函数。fixture中的代码可以定制,满足多变的测试需求,包括定义传入测试中的数据集,配置测试前系统的初始状态,为批量测试提供数据源,等等。 #!/usr/bin/python3 #-*- conding:ut 阅读全文
posted @ 2020-07-20 22:40 静心&得意 阅读(584) 评论(0) 推荐(0) 编辑
摘要: 标记 pytest提供了标记机制,运行使用marker对测试用例做标记。一个测试用例可以有多个marker,一个marker也可以用来标记多个测试用例 自定义标记 test_003.py #!/usr/bin/python3 #-*- conding:utf-8 -*- import pytest 阅读全文
posted @ 2020-07-20 22:39 静心&得意 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 断言 pytest允许在assert关键字后面添加任何表达式(assert )。如果表达式的值通过bool转换后等于False,则意味着用例执行失败。 断言声明 #!/usr/bin/python3 #-*- conding:utf-8 -*- def test_one(): assert 1 == 阅读全文
posted @ 2020-07-20 22:37 静心&得意 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 参数化 pytest使用parametrize标记实现参数化 @pytest.mark.parametrize(argnames,argvalues) parametrize()的第一个参数时用逗号分割的的字符串列表,第二个参数时一个值列表 #!/usr/bin/python3 #-*- condi 阅读全文
posted @ 2020-07-20 22:36 静心&得意 阅读(194) 评论(0) 推荐(0) 编辑
摘要: pytest入门 一、安装pytest pip install pytest 二、运行pytest pytest [options] [file_or_dir] [file_or_dir] [...] 如果不提供任何参数,pytest会在当前目录以及子目录下寻找测试文件,然后运行测试用例,如果提供了 阅读全文
posted @ 2020-07-20 22:32 静心&得意 阅读(119) 评论(0) 推荐(0) 编辑