Skip to content

Commit 7d4f2b3

Browse files
authored
tests: turn widget leaks into warning (#435)
turn leaks into warning
1 parent b13f8b7 commit 7d4f2b3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tests/conftest.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
from collections.abc import Iterator
13
from pathlib import Path
24
from typing import TYPE_CHECKING
35
from unittest.mock import patch
@@ -15,15 +17,17 @@
1517

1618
# to create a new CMMCorePlus() for every test
1719
@pytest.fixture(autouse=True)
18-
def global_mmcore():
20+
def global_mmcore() -> Iterator[CMMCorePlus]:
1921
mmc = CMMCorePlus()
2022
mmc.loadSystemConfiguration(TEST_CONFIG)
2123
with patch.object(_mmcore_plus, "_instance", mmc):
2224
yield mmc
2325

2426

2527
@pytest.fixture(autouse=True)
26-
def _run_after_each_test(request: "FixtureRequest", qapp: "QApplication"):
28+
def _run_after_each_test(
29+
request: "FixtureRequest", qapp: "QApplication"
30+
) -> Iterator[None]:
2731
"""Run after each test to ensure no widgets have been left around.
2832
2933
When this test fails, it means that a widget being tested has an issue closing
@@ -51,4 +55,8 @@ def _run_after_each_test(request: "FixtureRequest", qapp: "QApplication"):
5155
return
5256

5357
test = f"{request.node.path.name}::{request.node.originalname}"
54-
raise AssertionError(f"topLevelWidgets remaining after {test!r}: {remaining}")
58+
warnings.warn(
59+
f"topLevelWidgets remaining after {test!r}: {remaining}",
60+
UserWarning,
61+
stacklevel=2,
62+
)

0 commit comments

Comments
 (0)