File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -291,3 +291,27 @@ def test1():
291
291
res = testdir .inline_run ()
292
292
passed = 1 if apply_mark else 0
293
293
res .assertoutcome (passed = passed , failed = int (not passed ))
294
+
295
+
296
+ def test_logging_fails_lineno (testdir ):
297
+ """
298
+ Test that tests when failing because log messages were emitted report
299
+ the correct line number.
300
+
301
+ :type testdir: _pytest.pytester.TmpTestdir
302
+ """
303
+ testdir .makeini (
304
+ """
305
+ [pytest]
306
+ qt_log_level_fail = WARNING
307
+ """
308
+ )
309
+ testdir .makepyfile (
310
+ """
311
+ from pytestqt.qt_compat import qWarning
312
+ def test_foo():
313
+ qWarning('this is a WARNING message')
314
+ """
315
+ )
316
+ res = testdir .runpytest ()
317
+ res .stdout .fnmatch_lines ('*test_logging_fails_lineno.py:2: Failure:*' )
Original file line number Diff line number Diff line change @@ -799,8 +799,9 @@ class _QtLogLevelErrorRepr(TerminalRepr):
799
799
800
800
def __init__ (self , item , level ):
801
801
msg = 'Failure: Qt messages with level {0} or above emitted'
802
- path , line , _ = item .location
803
- self .fileloc = ReprFileLocation (path , line , msg .format (level .upper ()))
802
+ path , line_index , _ = item .location
803
+ self .fileloc = ReprFileLocation (path , lineno = line_index + 1 ,
804
+ message = msg .format (level .upper ()))
804
805
self .sections = []
805
806
806
807
def addsection (self , name , content , sep = "-" ):
You can’t perform that action at this time.
0 commit comments