Create LogCaptureHandler if necessary (closes #6240)

This commit is contained in:
Felix Nieuwenhuizen
2019-11-27 11:50:22 +01:00
parent 6df0b9c41a
commit 4dfc461036
4 changed files with 39 additions and 1 deletions

View File

@@ -613,7 +613,13 @@ class LoggingPlugin:
with catching_logs(self.log_file_handler, level=self.log_file_level):
yield
else:
yield
# Add a dummy handler to ensure logging.root.handlers is not empty.
# If it were empty, then a `logging.warning()` call (and similar) during collection
# would trigger a `logging.basicConfig()` call, which would add a `StreamHandler`
# handler, which would cause all subsequent logs which reach the root to be also
# printed to stdout, which we don't want (issue #6240).
with catching_logs(logging.NullHandler()):
yield
@contextmanager
def _runtest_for(self, item, when):