Skip to content

Commit

Permalink
logging: yield from _runtest_for instead of contextmanager
Browse files Browse the repository at this point in the history
Avoid the slight overhead of contextmanager.
  • Loading branch information
bluetech committed May 12, 2020
1 parent 59e3e6a commit 363db7e
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/_pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ def pytest_collection(self) -> Generator[None, None, None]:
else:
yield

@contextmanager
def _runtest_for(
self, item: Optional[nodes.Item], when: str
) -> Generator[None, None, None]:
Expand Down Expand Up @@ -659,35 +658,29 @@ def _runtest_for(

@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):
Expand Down

0 comments on commit 363db7e

Please sign in to comment.