diff --git a/_pytest/logging.py b/_pytest/logging.py index f7b4dc383..8d6208f1a 100644 --- a/_pytest/logging.py +++ b/_pytest/logging.py @@ -189,6 +189,7 @@ class LogCaptureFixture(object): """ logger_name = logger logger = logging.getLogger(logger_name) + # save the original log-level to restore it during teardown self._initial_log_levels.setdefault(logger_name, logger.level) logger.setLevel(level) diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py index 24f015d09..044088e1e 100644 --- a/testing/logging/test_reporting.py +++ b/testing/logging/test_reporting.py @@ -171,22 +171,17 @@ def test_log_cli_default_level(testdir): assert plugin.log_cli_handler.level == logging.NOTSET logging.getLogger('catchlog').info("INFO message won't be shown") logging.getLogger('catchlog').warning("WARNING message will be shown") - print('PASSED') ''') testdir.makeini(''' [pytest] log_cli=true ''') - result = testdir.runpytest('-s') + result = testdir.runpytest() # fnmatch_lines does an assertion internally result.stdout.fnmatch_lines([ - 'test_log_cli_default_level.py*', - 'PASSED', # 'PASSED' on its own line because the log message prints a new line - ]) - result.stdout.fnmatch_lines([ - '*WARNING message will be shown*', + 'test_log_cli_default_level.py*WARNING message will be shown*', ]) assert "INFO message won't be shown" not in result.stdout.str() # make sure that that we get a '0' exit code for the testsuite @@ -214,12 +209,9 @@ def test_log_cli_level(testdir): # fnmatch_lines does an assertion internally result.stdout.fnmatch_lines([ - 'test_log_cli_level.py*', + 'test_log_cli_level.py*This log message will be shown', 'PASSED', # 'PASSED' on its own line because the log message prints a new line ]) - result.stdout.fnmatch_lines([ - "* This log message will be shown" - ]) for line in result.outlines: try: assert "This log message won't be shown" in line @@ -234,12 +226,9 @@ def test_log_cli_level(testdir): # fnmatch_lines does an assertion internally result.stdout.fnmatch_lines([ - 'test_log_cli_level.py*', + 'test_log_cli_level.py* This log message will be shown', 'PASSED', # 'PASSED' on its own line because the log message prints a new line ]) - result.stdout.fnmatch_lines([ - "* This log message will be shown" - ]) for line in result.outlines: try: assert "This log message won't be shown" in line @@ -273,12 +262,9 @@ def test_log_cli_ini_level(testdir): # fnmatch_lines does an assertion internally result.stdout.fnmatch_lines([ - 'test_log_cli_ini_level.py*', + 'test_log_cli_ini_level.py* This log message will be shown', 'PASSED', # 'PASSED' on its own line because the log message prints a new line ]) - result.stdout.fnmatch_lines([ - "* This log message will be shown" - ]) for line in result.outlines: try: assert "This log message won't be shown" in line