File: test_coloredlogs.py

package info (click to toggle)
python-picologging 0.9.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 752 kB
  • sloc: python: 3,921; cpp: 2,430; makefile: 41; sh: 18
file content (33 lines) | stat: -rw-r--r-- 750 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import io

try:
    import coloredlogs

    has_libs = True
except ImportError:
    has_libs = False

import pytest

import picologging as logging


@pytest.mark.skipif(not has_libs, reason="Missing libraries")
def test_coloredlogs_logger():
    # Setup colored logger
    stream = io.StringIO()

    logger = logging.getLogger()
    logger.addHandler(logging.StreamHandler(stream))
    coloredlogs.install(logger=logger, level="INFO")

    logger.info("Info message")
    logger.warning("Warning message")
    logger.error("Error message")
    logger.critical("Critical message")

    log = stream.getvalue()
    assert "Info message" in log
    assert "Warning message" in log
    assert "Error message" in log
    assert "Critical message" in log