From ce0f2187936cebed1a75202530a672249c3f5438 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 17 May 2020 14:58:04 +0300 Subject: [PATCH] logging: yield from _runtest_for instead of contextmanager Avoid the slight overhead of contextmanager. --- src/_pytest/logging.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index 61d689263..55175cec5 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -625,7 +625,6 @@ class LoggingPlugin: with catching_logs(logging.NullHandler()): yield - @contextmanager def _runtest_for( self, item: Optional[nodes.Item], when: str ) -> Generator[None, None, None]: @@ -662,35 +661,29 @@ class LoggingPlugin: @pytest.hookimpl(hookwrapper=True) def pytest_runtest_setup(self, item): - with self._runtest_for(item, "setup"): - yield + yield from self._runtest_for(item, "setup") @pytest.hookimpl(hookwrapper=True) def pytest_runtest_call(self, item): - with self._runtest_for(item, "call"): - yield + yield from self._runtest_for(item, "call") @pytest.hookimpl(hookwrapper=True) def pytest_runtest_teardown(self, item): - with self._runtest_for(item, "teardown"): - yield + yield from self._runtest_for(item, "teardown") @pytest.hookimpl(hookwrapper=True) def pytest_runtest_logstart(self): if self.log_cli_handler: self.log_cli_handler.reset() - with self._runtest_for(None, "start"): - yield + yield from self._runtest_for(None, "start") @pytest.hookimpl(hookwrapper=True) def pytest_runtest_logfinish(self): - with self._runtest_for(None, "finish"): - yield + yield from self._runtest_for(None, "finish") @pytest.hookimpl(hookwrapper=True) def pytest_runtest_logreport(self): - with self._runtest_for(None, "logreport"): - yield + yield from self._runtest_for(None, "logreport") @pytest.hookimpl(hookwrapper=True, tryfirst=True) def pytest_sessionfinish(self):