[docs]defpytest_addoption(parser):defIFO():parser.addoption("--IFO",default="",help="IFO's to run (default:all)")defwield_collectonly():parser.addoption("--wield-collect-only","--ws-co",dest="ws_collectonly",action="store_true",default=None,help="Print test items in a custom format for wield")defWS_SKIP_SLOW():parser.addoption("--ws-skip-slow",action="store_true",help="Skip slow tests (marked with ws_slow)")wield.pytest.pytest_addoption(parser,IFO=IFO,wield_collectonly=wield_collectonly,WS_SKIP_SLOW=WS_SKIP_SLOW)
[docs]defpytest_collection_modifyitems(config,items):skip_slow=pytest.mark.skip(reason="marked ws_slow and --ws-skip-slow indicated")ifconfig.getoption("--ws-skip-slow"):foriteminitems:if"ws_slow"initem.keywords:item.add_marker(skip_slow)
[docs]@pytest.hookimpl()defpytest_report_collectionfinish(config,start_path,items):lines=[]ifconfig.option.ws_collectonlyisnotNone:stack=[]indent=""foriteminitems:needed_collectors=item.listchain()[1:]# strip root nodewhilestack:ifstack==needed_collectors[:len(stack)]:breakstack.pop()forcolinneeded_collectors[len(stack):]:stack.append(col)indent=(len(stack)-1)*" "relp=os.path.relpath(col.path,start_path)# TODO, find a way to avoid using print?# Other pytest things use the TerminalReporter# but it is difficult to prevent other output from collect-only# if trying to use that..print('{}{}::{}::{}'.format(indent,col.__class__.__name__,col.name,relp))pytest.exit('Done!')returnlineselse:return
[docs]@pytest.hookimpl(hookwrapper=True)defpytest_runtest_logreport(report):"""Stores captured report output by coordinating with the "capture" fixture """yieldifreport.when=='call':# print("HOOKWRAP", report.nodeid, wield.pytest.fixtures._node_capture)ifwield.pytest.fixtures._node_captureisnotNone:nodeid_from,location_from=wield.pytest.fixtures._node_captureifreport.nodeid==nodeid_from:# text = report.longreprtext or report.full_text# make sure the folder existsos.makedirs(os.path.split(location_from)[0],exist_ok=True)# write the log contentwithopen(location_from,"w")asF:F.write('status: {}\n'.format(report.outcome))F.write('duration: {:.3f}s\n'.format(report.duration))forsectioninreport.sections:header,content=sectionF.write(header)F.write('\n')F.write(content)# testing# longreprtext is only filled out on failure by pytest# otherwise will be None.# Use full_text if longreprtext is None-ish# we added full_text elsewhere in this file.text=report.longreprtextiftext:F.write('captured errors:\n')F.write(text)# print("================== report A ====================")# print(report.when, report.nodeid, wield.pytest.fixtures._node_capture)# print("================== report B ====================")# print(report.sections)# print("================== report C ====================")# print(report.longreprtext)# print("================== report D ====================")return
[docs]defpytest_configure(config):""" Setup collectonly """# run wield's as wellfromwield.pytestimportpytest_configurepytest_configure(config)ifconfig.option.ws_collectonlyisnotNone:ifnotconfig.option.collectonly:config.option.collectonly=Trueconfig.option.htmlpath=""passconfig.addinivalue_line("markers","ws_slow: mark test as slow (deselect with --ws-skip-slow)")config.addinivalue_line("markers","largemem: mark test as using a lot of memory")config.addinivalue_line("usefixtures","current_pytest_request")