pytest灵魂产物
1.pytest:
默认命名规则:
- 测试类必须以TestXxx形式书写,即以Test开头,不能带有init方法
- 测试文件以
test_*.py
开头(以*_test.py
结尾也可以) - 测试函数以test_开头
- 断言使用基本的 assert 即可
实现一个简单的pytest project:
pydemo
--cases
--__init__.py
--test_order.py
--test_shipping.py
--conftest.py
--pytest.ini
--pytest.log
conftest.py:
作用提供全局灯具函数和全局调用工具方法
如接口登陆获取token
import pytest
import uuid
pytest.ini:
pytest 的配置文件:
作用配置pytest的参数配置
[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg file found:
markers (linelist): markers for test functions
empty_parameter_set_mark (string):
default marker for empty parametersets
norecursedirs (args): directory patterns to avoid for recursion
testpaths (args): directories to search for tests when no files or directories are given in the command line.
filterwarnings (linelist):
Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.
usefixtures (args): list of default fixtures to be used with this project
python_files (args): glob-style file patterns for Python test module discovery
python_classes (args):
prefixes or glob names for Python test class discovery
python_functions (args):
prefixes or glob names for Python test function and method discovery
disable_test_id_escaping_and_forfeit_all_rights_to_community_support (bool):
disable string escape non-ascii characters, might cause unwanted side effects(use at your own risk)
console_output_style (string):
console output: "classic", or with additional progress information ("progress" (percentage) | "count").
xfail_strict (bool): default for the strict parameter of xfail markers when not given explicitly (default: False)
enable_assertion_pass_hook (bool):
Enables the pytest_assertion_pass