Example #1
0
    def _runtest_for_main(self, item: nodes.Item,
                          when: str) -> Generator[None, None, None]:
        """Implements the internals of pytest_runtest_xxx() hook."""
        with catching_logs(LogCaptureHandler(),
                           formatter=self.formatter,
                           level=self.log_level) as log_handler:
            if self.log_cli_handler:
                self.log_cli_handler.set_when(when)

            if item is None:
                yield  # run the test
                return

            if not hasattr(item, "catch_log_handlers"):
                item.catch_log_handlers = {
                }  # type: ignore[attr-defined]  # noqa: F821
            item.catch_log_handlers[
                when] = log_handler  # type: ignore[attr-defined]  # noqa: F821
            item.catch_log_handler = log_handler  # type: ignore[attr-defined]  # noqa: F821
            try:
                yield  # run test
            finally:
                if when == "teardown":
                    del item.catch_log_handler  # type: ignore[attr-defined]  # noqa: F821
                    del item.catch_log_handlers  # type: ignore[attr-defined]  # noqa: F821

            if self.print_logs:
                # Add a captured log section to the report.
                log = log_handler.stream.getvalue().strip()
                item.add_report_section(when, "log", log)
Example #2
0
    def _runtest_for(self, item: nodes.Item, when: str) -> Generator[None, None, None]:
        """Implements the internals of pytest_runtest_xxx() hook."""
        with catching_logs(self.log_handler, level=self.log_level) as log_handler:
            log_handler.reset()
            item._store[catch_log_records_key][when] = log_handler.records
            item._store[catch_log_handler_key] = log_handler

            yield

            log = log_handler.stream.getvalue().strip()
            item.add_report_section(when, "log", log)
Example #3
0
    def item_capture(self, when: str, item: Item) -> Generator[None, None, None]:
        self.resume_global_capture()
        self.activate_fixture()
        try:
            yield
        finally:
            self.deactivate_fixture()
            self.suspend_global_capture(in_=False)

        out, err = self.read_global_capture()
        item.add_report_section(when, "stdout", out)
        item.add_report_section(when, "stderr", err)
Example #4
0
    def _runtest_for(self, item: nodes.Item,
                     when: str) -> Generator[None, None, None]:
        """Implements the internals of pytest_runtest_xxx() hook."""
        log_handler = LogCaptureHandler()
        log_handler.setFormatter(self.formatter)
        with catching_logs(log_handler, level=self.log_level):
            item._store[catch_log_handlers_key][when] = log_handler
            item._store[catch_log_handler_key] = log_handler

            yield

            log = log_handler.stream.getvalue().strip()
            item.add_report_section(when, "log", log)
Example #5
0
    def _runtest_for(self, item: nodes.Item, when: str) -> Generator[None, None, None]:
        """Implement the internals of the pytest_runtest_xxx() hooks."""
        with catching_logs(
            self.caplog_handler,
            level=self.log_level,
        ) as caplog_handler, catching_logs(
            self.report_handler,
            level=self.log_level,
        ) as report_handler:
            caplog_handler.reset()
            report_handler.reset()
            item.stash[caplog_records_key][when] = caplog_handler.records
            item.stash[caplog_handler_key] = caplog_handler

            yield

            log = report_handler.stream.getvalue().strip()
            item.add_report_section(when, "log", log)