How to collate pytest logging output to console?

Viewed 139

I'd like to collate logging output to console such that the repeated "----ClassName.TestName---, and "-- Captured log call---" lines are removed or limited to a single entry. The below simplified example, with output, demonstrates the problem.

desired output:

2020-08-14 13:51:50 INFO test[test_01]
2020-08-14 13:51:50 INFO test[test_02]
2020-08-14 13:51:50 INFO test[test_03]
========= short test summary info =====================================
PASSED tests/test_logging.py::Test_Logging::test_01
PASSED tests/test_logging.py::Test_Logging::test_02
PASSED tests/test_logging.py::Test_Logging::test_03

source code:

import logging
import pytest

@pytest.mark.testing
class Test_Logging:

    _logger = None

    def setup_method(self):
        self._logger = logging.getLogger('Test Logger')

    def test_01(self, request):
        self._logger.info(f"test[{request.node.name}]")

    def test_02(self, request):
        self._logger.info(f"test[{request.node.name}]")

    def test_03(self, request):
        self._logger.info(f"test[{request.node.name}]")

current output:

_____________ Test_Logging.test_01 ____________________________________
-------- Captured log call --------------------------------------------
2020-08-14 13:51:50 INFO test[test_01]
_____________ Test_Logging.test_02 ____________________________________
-------- Captured log call --------------------------------------------
2020-08-14 13:51:50 INFO test[test_02]
_____________ Test_Logging.test_03 ____________________________________
-------- Captured log call --------------------------------------------
2020-08-14 13:51:50 INFO test[test_03]
========= short test summary info =====================================
PASSED tests/test_logging.py::Test_Logging::test_01
PASSED tests/test_logging.py::Test_Logging::test_02
PASSED tests/test_logging.py::Test_Logging::test_03
0 Answers
Related