(2023-05-11) 在钩子函数pytest_sessionfinish中获取命令行输入的–env的参数,当读取全局变量汇中的host读取不到的时候,使用–env对应的参数作为项目环境的变量值

This commit is contained in:
floraachy
2023-05-17 17:28:33 +08:00
parent 2a8410b32f
commit af7ffc1de8

View File

@@ -71,7 +71,6 @@ def pytest_runtest_makereport(item, call):
# 获取调用结果的测试报告返回一个report对象
# report对象的属性包括whensteup, call, teardown三个值、nodeid(测试用例的名字)、outcome(用例的执行结果passed,failed)
report = outcome.get_result()
# TODO由于目前无法动态将用例数据中的title写入测试方法中的文档注释因此该处理方法暂时搁置
# 将测试方法的文档注释作为结果表的Description的值如果文档注释为空则测试方法名作为结果表的Description的值
report.description = str(item.function.__doc__)
report.nodeid = report.nodeid.encode("utf-8").decode("unicode_escape")
@@ -102,7 +101,8 @@ def pytest_sessionfinish(session, exitstatus):
在测试运行后修改Environment部分信息
"""
# 给环境表 添加 项目环境
session.config._metadata['项目环境'] = GLOBAL_VARS.get("host", "")
env = session.config.getoption("--env") # 可以获取到命令行参数指定的环境
session.config._metadata['项目环境'] = {GLOBAL_VARS.get("host", env)}
@pytest.hookimpl(hookwrapper=True)