From e30c39fe78cb8d3fe8379f032b66f7719b2e99c5 Mon Sep 17 00:00:00 2001 From: Camilo Date: Thu, 14 Dec 2017 01:55:22 -0500 Subject: [PATCH 1/3] fix non-passing tests for logging on pytest > 3.3.0 --- tests/test_logging.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_logging.py b/tests/test_logging.py index 1a010569..cadcdab9 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -17,6 +17,10 @@ def reset_logging(monkeypatch): logger.handlers = [] logger.setLevel(logging.NOTSET) + logging_plugin = pytest.config.pluginmanager.getplugin('logging-plugin') + pytest.config.pluginmanager.unregister(name='logging-plugin') + logging.root.handlers = [] + yield logging.root.handlers[:] = root_handlers @@ -25,6 +29,8 @@ def reset_logging(monkeypatch): logger.handlers = [] logger.setLevel(logging.NOTSET) + pytest.config.pluginmanager.register(logging_plugin, 'logging-plugin') + def test_logger(app): assert app.logger.name == 'flask.app' From 33fa58094701d5b1edbf13ddfe7c93b4c5821b63 Mon Sep 17 00:00:00 2001 From: Camilo Date: Thu, 14 Dec 2017 09:40:34 -0500 Subject: [PATCH 2/3] restore the logging plugin only if it was active to begin with --- tests/test_logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_logging.py b/tests/test_logging.py index cadcdab9..be4e76ca 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -29,7 +29,8 @@ def reset_logging(monkeypatch): logger.handlers = [] logger.setLevel(logging.NOTSET) - pytest.config.pluginmanager.register(logging_plugin, 'logging-plugin') + if logging_plugin: + pytest.config.pluginmanager.register(logging_plugin, 'logging-plugin') def test_logger(app): From 604cc758fb6601782745572452715fc295dda011 Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 14 Dec 2017 12:20:03 -0800 Subject: [PATCH 3/3] use config fixture, get plugin via unregister --- tests/test_logging.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_logging.py b/tests/test_logging.py index be4e76ca..80540e84 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -9,17 +9,17 @@ from flask.logging import default_handler, has_level_handler, \ @pytest.fixture(autouse=True) -def reset_logging(monkeypatch): +def reset_logging(pytestconfig): root_handlers = logging.root.handlers[:] + logging.root.handlers = [] root_level = logging.root.level logger = logging.getLogger('flask.app') logger.handlers = [] logger.setLevel(logging.NOTSET) - logging_plugin = pytest.config.pluginmanager.getplugin('logging-plugin') - pytest.config.pluginmanager.unregister(name='logging-plugin') - logging.root.handlers = [] + logging_plugin = pytestconfig.pluginmanager.unregister( + name='logging-plugin') yield @@ -30,7 +30,7 @@ def reset_logging(monkeypatch): logger.setLevel(logging.NOTSET) if logging_plugin: - pytest.config.pluginmanager.register(logging_plugin, 'logging-plugin') + pytestconfig.pluginmanager.register(logging_plugin, 'logging-plugin') def test_logger(app):