logging: yield from _runtest_for instead of contextmanager

Avoid the slight overhead of contextmanager.
This commit is contained in:
Ran Benita 2020-05-17 14:58:04 +03:00
parent 9effbe7425
commit ce0f218793
1 changed files with 6 additions and 13 deletions

View File

@ -625,7 +625,6 @@ class LoggingPlugin:
with catching_logs(logging.NullHandler()): with catching_logs(logging.NullHandler()):
yield yield
@contextmanager
def _runtest_for( def _runtest_for(
self, item: Optional[nodes.Item], when: str self, item: Optional[nodes.Item], when: str
) -> Generator[None, None, None]: ) -> Generator[None, None, None]:
@ -662,35 +661,29 @@ class LoggingPlugin:
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_setup(self, item): def pytest_runtest_setup(self, item):
with self._runtest_for(item, "setup"): yield from self._runtest_for(item, "setup")
yield
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item): def pytest_runtest_call(self, item):
with self._runtest_for(item, "call"): yield from self._runtest_for(item, "call")
yield
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_teardown(self, item): def pytest_runtest_teardown(self, item):
with self._runtest_for(item, "teardown"): yield from self._runtest_for(item, "teardown")
yield
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logstart(self): def pytest_runtest_logstart(self):
if self.log_cli_handler: if self.log_cli_handler:
self.log_cli_handler.reset() self.log_cli_handler.reset()
with self._runtest_for(None, "start"): yield from self._runtest_for(None, "start")
yield
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logfinish(self): def pytest_runtest_logfinish(self):
with self._runtest_for(None, "finish"): yield from self._runtest_for(None, "finish")
yield
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logreport(self): def pytest_runtest_logreport(self):
with self._runtest_for(None, "logreport"): yield from self._runtest_for(None, "logreport")
yield
@pytest.hookimpl(hookwrapper=True, tryfirst=True) @pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_sessionfinish(self): def pytest_sessionfinish(self):