参考资料:https://www.cnblogs.com/yoyoketang/p/14042224.html
当log_cli = 1 后 运行 pytest 命令,报告会按每条用例显示结果 ;
当log_cli = 0 后 运行 pytest 命令,在控制台输出是按每个模块显示运行结果 ;
默认为 False ,0 ;
疑问:为什么我把 log_cli = 0 或 1 都是一样的结果,都显示 模块 : 测试用例 ?
现象和代码如下:
代码目录结构如下:
pytest.ini 代码如下:
[pytest] log_cli = 0 addopts = -v -s
conftest.py 代码如下:
import pytest @pytest.fixture(autouse=True) def get_ini(pytestconfig): # 读取ini配置信息 # 读取 log_cli配置 log_cli = pytestconfig.getini('log_cli') print("获取到markers :%s" % log_cli) addopts = pytestconfig.getini('addopts') print("获取到addopts的配置:%s " % addopts)
test_kk.py 代码如下:
def test_1(): print('\n============测试 test_1 =============')
当 log_cli 设置为 0 执行结果如下:
D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day11\kk>pytest =================================================================================== test session starts ==================================================================================== platform win32 -- Python 3.8.6, pytest-5.4.3, py-1.10.0, pluggy-0.13.1 -- c:\skyworkspace\worktools\python\python38\python.exe cachedir: .pytest_cache Metadata: {'Python': '3.8.6', 'Platform': 'Windows-10-10.0.19041-SP0', 'Packages': {'pytest': '5.4.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'allure-pytest': '2.9.43', 'html': '2.1.1', 'Metadata': '1.11.0'}, 'JAVA_HOME': 'C:\\SkyWorkSpace\\WorkTools\\Java\\jdk1.8\\jdk1.8.0_271'} rootdir: D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day11, inifile: pytest.ini plugins: allure-pytest-2.9.43, html-2.1.1, Metadata-1.11.0 collected 1 item test_kk.py::test_1 获取到markers :False 获取到addopts的配置:['-v', '-s'] ============测试 test_1 ============= PASSED ==================================================================================== 1 passed in 0.02s =====================================================================================
当 log_cli 设置为 1 执行结果如下:
D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day11\kk>pytest =================================================================================== test session starts ==================================================================================== platform win32 -- Python 3.8.6, pytest-5.4.3, py-1.10.0, pluggy-0.13.1 -- c:\skyworkspace\worktools\python\python38\python.exe cachedir: .pytest_cache Metadata: {'Python': '3.8.6', 'Platform': 'Windows-10-10.0.19041-SP0', 'Packages': {'pytest': '5.4.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'allure-pytest': '2.9.43', 'html': '2.1.1', 'Metadata': '1.11.0'}, 'JAVA_HOME': 'C:\\SkyWorkSpace\\WorkTools\\Java\\jdk1.8\\jdk1.8.0_271'} rootdir: D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day11, inifile: pytest.ini plugins: allure-pytest-2.9.43, html-2.1.1, Metadata-1.11.0 collected 1 item test_kk.py::test_1 获取到markers :True 获取到addopts的配置:['-v', '-s'] ============测试 test_1 ============= PASSED ==================================================================================== 1 passed in 0.02s ===================================================================================== D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day11\kk>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。