pytest 搜集所有的用例
conftest.py
def pytest_collection_modifyitems(session, config, items):
case_name_dict = dict()
for item in items:
case_name = item.name
if '[' in item.name:
case_name = item.name.split('[')[0]
if item.module.__name__ in case_name_dict:
case_name_dict[item.module.__name__].append(case_name)
else:
case_name_dict[item.module.__name__] = [case_name]
# case_dict = {
# "nodeid": item.nodeid,
# "name": item.name,
# "location": f"{item.fspath}:",
# "module": item.module.__name__,
# "qualname": item.originalname or item.name,
# "fixturenames": item.fixturenames,
# "path": case_path,
# }
# case_name_dict[case_name] = case_dict
with open("collected_tests.json", "w") as f:
json.dump(case_name_dict, f, indent=4)