@@ -302,14 +302,14 @@ def test_logging_and_immediate_setupteardown(self, testdir):
302
302
"""\
303
303
import logging
304
304
def setup_function(function):
305
- logging.warn ("hello1")
305
+ logging.warning ("hello1")
306
306
307
307
def test_logging():
308
- logging.warn ("hello2")
308
+ logging.warning ("hello2")
309
309
assert 0
310
310
311
311
def teardown_function(function):
312
- logging.warn ("hello3")
312
+ logging.warning ("hello3")
313
313
assert 0
314
314
"""
315
315
)
@@ -328,14 +328,14 @@ def test_logging_and_crossscope_fixtures(self, testdir):
328
328
"""\
329
329
import logging
330
330
def setup_module(function):
331
- logging.warn ("hello1")
331
+ logging.warning ("hello1")
332
332
333
333
def test_logging():
334
- logging.warn ("hello2")
334
+ logging.warning ("hello2")
335
335
assert 0
336
336
337
337
def teardown_module(function):
338
- logging.warn ("hello3")
338
+ logging.warning ("hello3")
339
339
assert 0
340
340
"""
341
341
)
@@ -354,7 +354,7 @@ def test_conftestlogging_is_shown(self, testdir):
354
354
"""\
355
355
import logging
356
356
logging.basicConfig()
357
- logging.warn ("hello435")
357
+ logging.warning ("hello435")
358
358
"""
359
359
)
360
360
# make sure that logging is still captured in tests
@@ -375,7 +375,7 @@ def test_conftestlogging_and_test_logging(self, testdir):
375
375
"""\
376
376
def test_hello():
377
377
import logging
378
- logging.warn ("hello433")
378
+ logging.warning ("hello433")
379
379
assert 0
380
380
"""
381
381
)
@@ -385,6 +385,40 @@ def test_hello():
385
385
assert "something" not in result .stderr .str ()
386
386
assert "operation on closed file" not in result .stderr .str ()
387
387
388
+ def test_logging_after_cap_stopped (self , testdir ):
389
+ testdir .makeconftest (
390
+ """\
391
+ import pytest
392
+ import logging
393
+
394
+ log = logging.getLogger(__name__)
395
+
396
+ @pytest.fixture
397
+ def log_on_teardown():
398
+ yield
399
+ log.warning('Logging on teardown')
400
+ """
401
+ )
402
+ # make sure that logging is still captured in tests
403
+ p = testdir .makepyfile (
404
+ """\
405
+ def test_hello(log_on_teardown):
406
+ import logging
407
+ logging.warning("hello433")
408
+ assert 1
409
+ raise KeyboardInterrupt()
410
+ """
411
+ )
412
+ result = testdir .runpytest_subprocess (p , "--log-cli-level" , "info" )
413
+ assert result .ret != 0
414
+ result .stdout .fnmatch_lines (
415
+ ["*WARNING*hello433*" , "*WARNING*Logging on teardown*" ]
416
+ )
417
+ assert (
418
+ "AttributeError: 'NoneType' object has no attribute 'resume_capturing'"
419
+ not in result .stderr .str ()
420
+ )
421
+
388
422
389
423
class TestCaptureFixture (object ):
390
424
@pytest .mark .parametrize ("opt" , [[], ["-s" ]])
@@ -1300,13 +1334,13 @@ def test_capturing_and_logging_fundamentals(testdir, method):
1300
1334
Capture=capture.%s)
1301
1335
cap.start_capturing()
1302
1336
1303
- logging.warn ("hello1")
1337
+ logging.warning ("hello1")
1304
1338
outerr = cap.readouterr()
1305
1339
print("suspend, captured %%s" %%(outerr,))
1306
- logging.warn ("hello2")
1340
+ logging.warning ("hello2")
1307
1341
1308
1342
cap.pop_outerr_to_orig()
1309
- logging.warn ("hello3")
1343
+ logging.warning ("hello3")
1310
1344
1311
1345
outerr = cap.readouterr()
1312
1346
print("suspend2, captured %%s" %% (outerr,))
0 commit comments