1
- import textwrap
2
1
import pytest
3
2
import sys
4
3
from pytestqt .plugin import capture_exceptions , format_captured_exceptions
5
4
from pytestqt .qt_compat import QtGui , Qt , QtCore
6
5
7
6
7
+ pytest_plugins = 'pytester'
8
+
9
+
8
10
class Receiver (QtCore .QObject ):
9
11
"""
10
12
Dummy QObject subclass that raises an error on receiving events if
@@ -45,4 +47,40 @@ def test_format_captured_exceptions():
45
47
lines = obtained_text .splitlines ()
46
48
47
49
assert 'Qt exceptions in virtual methods:' in lines
48
- assert 'ValueError: errors were made' in lines
50
+ assert 'ValueError: errors were made' in lines
51
+
52
+
53
+ @pytest .mark .parametrize ('no_capture_by_marker' , [True , False ])
54
+ def test_no_capture (testdir , no_capture_by_marker ):
55
+ """
56
+ Make sure options that disable exception capture are working (either marker
57
+ or ini configuration value).
58
+ :type testdir: TmpTestdir
59
+ """
60
+ if no_capture_by_marker :
61
+ marker_code = '@pytest.mark.qt_no_exception_capture'
62
+ else :
63
+ marker_code = ''
64
+ testdir .makeini ('''
65
+ [pytest]
66
+ qt_no_exception_capture = 1
67
+ ''' )
68
+ testdir .makepyfile ('''
69
+ import pytest
70
+ from pytestqt.qt_compat import QtGui, QtCore
71
+
72
+ class MyWidget(QtGui.QWidget):
73
+
74
+ def mouseReleaseEvent(self, ev):
75
+ raise RuntimeError
76
+
77
+ {marker_code}
78
+ def test_widget(qtbot):
79
+ w = MyWidget()
80
+ qtbot.addWidget(w)
81
+ qtbot.mouseClick(w, QtCore.Qt.LeftButton)
82
+ ''' .format (marker_code = marker_code ))
83
+ result = testdir .runpytest ('-s' )
84
+ # when it fails, it fails with "1 passed, 1 error in", so ensure
85
+ # it is passing without errors
86
+ result .stdout .fnmatch_lines ('*1 passed in*' )
0 commit comments