Skip to content

Commit

Permalink
Fix test_exceptions_dont_leak in Python 3.12 (#535)
Browse files Browse the repository at this point in the history
Fixes #532
  • Loading branch information
nicoddemus authored Jan 6, 2024
1 parent 36a436d commit ed5668a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
UNRELEASED
----------

- Fixed exception handling so they are properly cleared in Python 3.12, due to the new `sys.last_exc <https://docs.python.org/3/library/sys.html#sys.last_exc>`__ attribute (`#532`_).

.. _#532: https://github.com/pytest-dev/pytest-qt/issues/532

4.3.1 (2023-12-22)
------------------

Expand Down
2 changes: 2 additions & 0 deletions src/pytestqt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def fail_if_exceptions_occurred(self, when):
prefix = "%s ERROR: " % when
msg = prefix + format_captured_exceptions(exceptions)
del exceptions[:] # Don't keep exceptions alive longer.
if hasattr(sys, "last_exc"):
sys.last_exc = None
pytest.fail(msg, pytrace=False)


Expand Down
3 changes: 0 additions & 3 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,6 @@ def event(self, ev):


@exception_capture_pyside6
@pytest.mark.skipif(
sys.version_info[:2] == (3, 12), reason="#532 requires investigation"
)
def test_exceptions_dont_leak(testdir):
"""
Ensure exceptions are cleared when an exception occurs and don't leak (#187).
Expand Down

0 comments on commit ed5668a

Please sign in to comment.