def run_fictitious_testprotocol(item): """ REMINDER: Tests have already run on subprocess. Here we just need to convince the current pytest process that the tests have already run and to collect their reports. """ call = CallInfo.from_call(lambda: True, when="setup", reraise=(Exit, )) item.ihook.pytest_runtest_makereport(item=item, call=call) call = CallInfo.from_call(lambda: True, when="call", reraise=(Exit, )) item.ihook.pytest_runtest_makereport(item=item, call=call) call = CallInfo.from_call(lambda: True, when="teardown", reraise=(Exit, )) item.ihook.pytest_runtest_makereport(item=item, call=call)
def pytest_runtest_makereport(item, call): if isinstance(item, TestCaseFunction): if item._excinfo: call.excinfo = item._excinfo.pop(0) try: del call.result except AttributeError: pass unittest = sys.modules.get("unittest") if unittest and call.excinfo and call.excinfo.errisinstance( unittest.SkipTest): # let's substitute the excinfo with a pytest.skip one call2 = CallInfo.from_call( lambda: pytest.skip(str(call.excinfo.value)), call.when) call.excinfo = call2.excinfo
def pytest_pyfunc_call(pyfuncitem): if not pyfuncitem.config.option.reload_loop: return None else: testfunction = pyfuncitem.obj iscoroutinefunction = getattr(inspect, "iscoroutinefunction", None) if iscoroutinefunction is not None and iscoroutinefunction( testfunction): msg = "Coroutine functions are not natively supported and have been skipped.\n" msg += "You need to install a suitable plugin for your async framework, for example:\n" msg += " - pytest-asyncio\n" msg += " - pytest-trio\n" msg += " - pytest-tornasync" warnings.warn(pytest.PytestWarning(msg.format(pyfuncitem.nodeid))) pytest.skip( msg= "coroutine function and no async plugin installed (see warnings)" ) funcargs = pyfuncitem.funcargs testargs = { arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames } passing = False while not passing: info = CallInfo.from_call(lambda: testfunction(**testargs), when="call", reraise=None) # if info.excinfo: if info.excinfo: # build the pytest report report = pyfuncitem.ihook.pytest_runtest_makereport( item=pyfuncitem, call=info) _enter_pdb(pyfuncitem, info.excinfo, report) else: passing = True # after you've successfully gotten the test to pass run it one more time # (this hack exists because of the hookwrapper logic) return info
def fake_process(trace_fname): config = ctype(otype(trace_fname, 4), PytestPluginManager(), lambda x, y: 0) plugin = ApiritifPytestPlugin(config) next(plugin.pytest_runtest_setup(None)) yield node = Node._create("test", nodeid="tst", config=config, session="some") node._report_sections = [] node.location = [] node.user_properties = [] call = CallInfo.from_call(lambda: 1, 'call') report = TestReport.from_item_and_call(node, call) result = _Result(report, None) gen = plugin.pytest_runtest_makereport(node, call) next(gen) try: gen.send(result) except StopIteration: pass plugin.pytest_sessionfinish(None)