pytest.ini配置文件(作用:用来修改配置pytest默认的运行规则)@H_404_3@
#coding=utf-8
[pytest]
filterwarnings =
error
ignore::UserWarning
ignore:function ham\(\) is deprecated:DeprecationWarning
addopts = -v -s
--strict
-m "level0 or level1"
--cache-clear
norecursedird = .svn -build tmP* .git .idea .pytest_cache
python_files = test_*.py
python_functions = test_run
markers =
level0 : smoketest
level1 : systemtest
- 配置参数含义
- filterwarnings:消除pytest执行警告(从版本开始3.1,pytest现在会在测试执行期间自动捕获警告并在会话结束时显示它们)
- addopts: 更改默认命令行选项,当我们用命令行运行时,需要输入多个参数,可在这里配置(比如:pytest -s test_001.py 配置后只需要 pytest test_001.py)
- norecursedird: pytest收集用例排除的文件
- python_files: 用例收集规则
- python_classes/python_functions: 类/函数收集规则
- markers: 指定mark标签
import pytest
class TestCase001:
def sum(self, x):
return x + 3
def test_001(self):
assert self.sum(1) == 3
def test_002(self):
assert self.sum(2) == 5
@pytest.mark.level0
def test_run(self):
assert sum(5) == 7
=================================== FAILURES ===================================
_____________________________ TestCase001.test_run _____________________________
self = <TestCase.Demo.test_demo_001.TestCase001 object at 0x13be5a3c8>
@pytest.mark.level0
def test_run(self):
> assert sum(5) == 7
E TypeError: 'int' object is not iterable
test_demo_001.py:16: TypeError
=========================== short test summary info ============================
Failed test_demo_001.py::TestCase001::test_run - TypeError: 'int' object is n...
============================== 1 Failed in 0.09s ===============================
Process finished with exit code 0
这里只运行了test_run(在ini中我们指定了python_functions和运行的mark)@H_404_3@
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。