@@ -302,14 +302,14 @@ def test_logging_and_immediate_setupteardown(self, testdir):
302302 """\
303303 import logging
304304 def setup_function(function):
305- logging.warn ("hello1")
305+ logging.warning ("hello1")
306306
307307 def test_logging():
308- logging.warn ("hello2")
308+ logging.warning ("hello2")
309309 assert 0
310310
311311 def teardown_function(function):
312- logging.warn ("hello3")
312+ logging.warning ("hello3")
313313 assert 0
314314 """
315315 )
@@ -328,14 +328,14 @@ def test_logging_and_crossscope_fixtures(self, testdir):
328328 """\
329329 import logging
330330 def setup_module(function):
331- logging.warn ("hello1")
331+ logging.warning ("hello1")
332332
333333 def test_logging():
334- logging.warn ("hello2")
334+ logging.warning ("hello2")
335335 assert 0
336336
337337 def teardown_module(function):
338- logging.warn ("hello3")
338+ logging.warning ("hello3")
339339 assert 0
340340 """
341341 )
@@ -354,7 +354,7 @@ def test_conftestlogging_is_shown(self, testdir):
354354 """\
355355 import logging
356356 logging.basicConfig()
357- logging.warn ("hello435")
357+ logging.warning ("hello435")
358358 """
359359 )
360360 # make sure that logging is still captured in tests
@@ -375,7 +375,7 @@ def test_conftestlogging_and_test_logging(self, testdir):
375375 """\
376376 def test_hello():
377377 import logging
378- logging.warn ("hello433")
378+ logging.warning ("hello433")
379379 assert 0
380380 """
381381 )
@@ -385,6 +385,40 @@ def test_hello():
385385 assert "something" not in result .stderr .str ()
386386 assert "operation on closed file" not in result .stderr .str ()
387387
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+
388422
389423class TestCaptureFixture (object ):
390424 @pytest .mark .parametrize ("opt" , [[], ["-s" ]])
@@ -1300,13 +1334,13 @@ def test_capturing_and_logging_fundamentals(testdir, method):
13001334 Capture=capture.%s)
13011335 cap.start_capturing()
13021336
1303- logging.warn ("hello1")
1337+ logging.warning ("hello1")
13041338 outerr = cap.readouterr()
13051339 print("suspend, captured %%s" %%(outerr,))
1306- logging.warn ("hello2")
1340+ logging.warning ("hello2")
13071341
13081342 cap.pop_outerr_to_orig()
1309- logging.warn ("hello3")
1343+ logging.warning ("hello3")
13101344
13111345 outerr = cap.readouterr()
13121346 print("suspend2, captured %%s" %% (outerr,))
0 commit comments