Skip to content

Commit b6767ef

Browse files
committed
Make sure context information with None attributes don't break the plugin
1 parent 6563f57 commit b6767ef

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pytestqt/_tests/test_logging.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,32 @@ def foo():
325325
])
326326
else:
327327
res.stdout.fnmatch_lines('*test_lineno_failure.py:2: Failure*')
328+
329+
330+
@pytest.mark.skipif(QT_API != 'pyqt5',
331+
reason='Context information only available in PyQt5')
332+
def test_context_none(testdir):
333+
"""
334+
Sometimes PyQt5 will emit a context with some/all attributes set as None
335+
instead of appropriate file, function and line number.
336+
337+
Test that when this happens the plugin doesn't break.
338+
339+
:type testdir: _pytest.pytester.TmpTestdir
340+
"""
341+
testdir.makepyfile(
342+
"""
343+
from pytestqt.qt_compat import QtWarningMsg
344+
345+
def test_foo(request):
346+
log_capture = request.node.qt_log_capture
347+
context = log_capture._Context(None, None, None)
348+
log_capture._handle(QtWarningMsg, "WARNING message", context)
349+
assert 0
350+
"""
351+
)
352+
res = testdir.runpytest()
353+
res.stdout.fnmatch_lines([
354+
'*Failure*',
355+
'*None:None:None:*',
356+
])

0 commit comments

Comments
 (0)