pytest framework_pytest.ini

pytest.ini
(1) Definition
is the configuration file of the pytest unit test framework, which implements functions such as changing the running mode
(2) Location is
in the root directory of the project
(3) Usage
Insert picture description here

[pytest]
addopts = -vs --html D:/se_frame/Reports/report.html
testpaths = D:/se_frame/TestCases
python_files = test*
python_classes = Test*
python_functions = test*
markers =
    smoke
    usermange
    product

This path must be an absolute path, otherwise the generated test report path will have problems
addopts: add some functions commonly used when pytest.main() is executed
testpaths: identify the test case of D:\se_frame\TestCases
python_files: identify the directory with TestCases The following file starting with test
python_classes: to identify the class starting with Test
python_functions: to identify the method starting with test
markers: mainly @pytest.mark.xxx It is used to classify test cases. For example, the first one is smoking use case

Common functions are as follows:

    """
    pytest参数详解:
    -s 表示输出陶氏信息,包括print打印的信息
    -v 表示更相信的信息
    -vs 一般一起用
    -n 支持分布式运行测试用例
    -k 根据用例的部分字符串指定测试用例
    --html 路径 生成测试报告
    """

Practical example:
The output of pytest.ini without -vs:

collected 13 items

test_1.py ..........Xs.                                                  [100%]

- generated html file: file://D:\se_frame\Cases\MapAaaCases\Reports\report.html -
================== 11 passed, 1 skipped, 1 xpassed in 0.33s ===================

The output of pytest.ini with -vs:

collected 13 items

test_1.py::Testlogin001::test_case_12 
启动浏览器
---进入要执行模块的的界面---
---3号用例完成---
---4号用例完成---
---5号用例完成---
---12号用例完成---
XPASS (该功能尚未完善,还在调测中)
退出浏览器

test_1.py::Testlogin001::test_case_13 SKIPPED (test_case_13用例还在...)
test_1.py::Testlogin2::test_case_14 
启动浏览器
---进入要执行模块的的界面---
---14号用例完成---
PASSED
退出浏览器

- generated html file: file://D:\se_frame\Cases\MapAaaCases\Reports\report.html -
================== 11 passed, 1 skipped, 1 xpassed in 0.13s ===================

Guess you like

Origin blog.csdn.net/weixin_45451320/article/details/113916427