Skip to content

Commit

Permalink
Improve "uncaught exception" message by mentioning Qt event loop inst…
Browse files Browse the repository at this point in the history
…ead of virtual methods

As suggested in:

#11 (comment)
  • Loading branch information
nicoddemus committed Feb 27, 2019
1 parent bafae02 commit 3443537
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
3.2.3 (unreleased)
------------------

- Improve message in uncaught exceptions by mentioning the Qt event loop instead of
Qt virtual methods (`#255`_).

.. _#255: https://github.com/pytest-dev/pytest-qt/pull/255

3.2.2 (2018-12-13)
------------------

Expand Down
2 changes: 1 addition & 1 deletion pytestqt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def format_captured_exceptions(exceptions):
from io import StringIO

stream = StringIO()
stream.write("Qt exceptions in virtual methods:\n")
stream.write("Exceptions caught in Qt event loop:\n")
sep = "_" * 80 + "\n"
stream.write(sep)
for (exc_type, value, tback) in exceptions:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@pytest.mark.parametrize("raise_error", [False, True])
def test_catch_exceptions_in_virtual_methods(testdir, raise_error):
"""
Catch exceptions that happen inside Qt virtual methods and make the
Catch exceptions that happen inside Qt's event loop and make the
tests fail if any.
:type testdir: _pytest.pytester.TmpTestdir
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_exceptions(qtbot):
)
result = testdir.runpytest()
if raise_error:
expected_lines = ["*Qt exceptions in virtual methods:*"]
expected_lines = ["*Exceptions caught in Qt event loop:*"]
if sys.version_info.major == 3:
expected_lines.append("RuntimeError: original error")
expected_lines.extend(["*ValueError: mistakes were made*", "*1 failed*"])
Expand All @@ -61,7 +61,7 @@ def test_format_captured_exceptions():
obtained_text = format_captured_exceptions(exceptions)
lines = obtained_text.splitlines()

assert "Qt exceptions in virtual methods:" in lines
assert "Exceptions caught in Qt event loop:" in lines
assert "ValueError: errors were made" in lines


Expand All @@ -78,7 +78,7 @@ def test_format_captured_exceptions_chained():
obtained_text = format_captured_exceptions(exceptions)
lines = obtained_text.splitlines()

assert "Qt exceptions in virtual methods:" in lines
assert "Exceptions caught in Qt event loop:" in lines
assert "ValueError: errors were made" in lines
assert "RuntimeError: error handling value error" in lines

Expand Down

0 comments on commit 3443537

Please sign in to comment.