Skip to content

Commit

Permalink
ENH: Only check for closed when test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Apr 9, 2024
1 parent 9a651b5 commit 84b0945
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,28 @@ def no_qt(monkeypatch):
if need_reload:
importlib.reload(pyvistaqt)
assert 'qtpy' in sys.modules


# Adapted from MNE-Python and
# https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures # noqa: E501

_phase_report_key = pytest.StashKey()


@pytest.fixture
def check_test_passed(request):
"""Return a function that checks if a test passed."""
def _test_passed():
if _phase_report_key not in request.node.stash:
return True
report = request.node.stash[_phase_report_key]
return "call" in report and report["call"].outcome == "passed"
return _test_passed


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
"""Stash the status of each item."""
outcome = yield
rep = outcome.get_result()
item.stash.setdefault(_phase_report_key, {})[rep.when] = rep
4 changes: 3 additions & 1 deletion tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_editor(qtbot, plotting):


@pytest.fixture()
def ensure_closed():
def ensure_closed(check_test_passed):
"""Ensure all plotters are closed."""
try:
from pyvista.plotting import close_all
Expand All @@ -291,6 +291,8 @@ def ensure_closed():
close_all() # this is necessary to test _ALL_PLOTTERS
assert len(_ALL_PLOTTERS) == 0
yield
if not check_test_passed():
return
WANT_AFTER = 0 if PV_VERSION >= Version('0.37') else 1
assert len(_ALL_PLOTTERS) == WANT_AFTER

Expand Down

0 comments on commit 84b0945

Please sign in to comment.