def test_colored_ansi_esc_caplogtext(pytester: Pytester) -> None:
    """Make sure that caplog.text does not contain ANSI escape sequences."""
    pytester.makepyfile(
        """
        import logging

        logger = logging.getLogger(__name__)

        def test_foo(caplog):
            logger.info('text going to logger from call')
            assert '\x1b' not in caplog.text
        """
    )
    result = pytester.runpytest("--log-level=INFO", "--color=yes")
    assert result.ret == 0
Make sure that caplog.text does not contain ANSI escape sequences.
testing/logging/test_reporting.py