From 493996e06b8f4597d9b0655eb10dcbb091b437bf Mon Sep 17 00:00:00 2001 From: Jonathan Karlsen Date: Mon, 4 Mar 2024 13:39:44 +0100 Subject: [PATCH] Remove import for _pytest.runner.call_runtest_hook Fixes incompatibility with pytest == 8.1.0 by internalizing call_runtest_hook function. --- flaky/flaky_pytest_plugin.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/flaky/flaky_pytest_plugin.py b/flaky/flaky_pytest_plugin.py index cd55f6e..ba18884 100644 --- a/flaky/flaky_pytest_plugin.py +++ b/flaky/flaky_pytest_plugin.py @@ -130,7 +130,23 @@ def call_and_report(self, item, when, log=True, **kwds): :type log: `bool` """ - call = runner.call_runtest_hook(item, when, **kwds) + def _call_runtest_hook(item, when, **kwds): + if when == "setup": + ihook = item.ihook.pytest_runtest_setup + elif when == "call": + ihook = item.ihook.pytest_runtest_call + elif when == "teardown": + ihook = item.ihook.pytest_runtest_teardown + else: + assert False, f"Unhandled runtest hook case: {when}" + reraise = (runner.Exit,) + if not item.config.getoption("usepdb", False): + reraise += (KeyboardInterrupt,) + return runner.CallInfo.from_call( + lambda: ihook(item=item, **kwds), when=when, reraise=reraise + ) + + call = _call_runtest_hook(item, when, **kwds) self._call_infos[item][when] = call hook = item.ihook report = hook.pytest_runtest_makereport(item=item, call=call)