Skip to content

Commit fd3dfe1

Browse files
committed
add hook to catch StashKey errors on teardown
1 parent 73e767c commit fd3dfe1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/core/engine_adapter/integration/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@
2727
logger = logging.getLogger(__name__)
2828

2929

30+
@pytest.hookimpl(tryfirst=True, wrapper=True)
31+
def pytest_fixture_post_finalizer(fixturedef: pytest.FixtureDef, request: pytest.FixtureRequest):
32+
try:
33+
yield
34+
except KeyError as e:
35+
# The tmp_path fixture frequently throws errors like:
36+
# - KeyError: <_pytest.stash.StashKey object at 0x79ba385fe1a0>
37+
# in its teardown. This causes pytest to mark the test as failed even though we have zero control over this behaviour.
38+
# So we log/swallow that particular error here rather than raising it
39+
if fixturedef.argname == "tmp_path" and "_pytest.stash.StashKey" in repr(e):
40+
request.node.add_report_section(
41+
"teardown", "stderr", f"Ignored tmp_path teardown error: {e}"
42+
)
43+
return
44+
raise
45+
46+
3047
@pytest.fixture
3148
def config(tmp_path: pathlib.Path) -> Config:
3249
return load_config_from_paths(

0 commit comments

Comments
 (0)