File: test_flags.py

package info (click to toggle)
logbook 1.7.0-1.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,140 kB
  • sloc: python: 6,558; makefile: 141
file content (32 lines) | stat: -rw-r--r-- 1,060 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
import pytest

import logbook

from .utils import capturing_stderr_context


def test_error_flag(logger):
    with capturing_stderr_context() as captured:
        with logbook.Flags(errors="print"):
            with logbook.Flags(errors="silent"):
                logger.warn("Foo {42}", "aha")
        assert captured.getvalue() == ""

        with logbook.Flags(errors="silent"):
            with logbook.Flags(errors="print"):
                logger.warn("Foo {42}", "aha")
        assert captured.getvalue() != ""

        with pytest.raises(Exception) as caught:
            with logbook.Flags(errors="raise"):
                logger.warn("Foo {42}", "aha")
        assert "Could not format message with provided arguments" in str(caught.value)


def test_disable_introspection(logger):
    with logbook.Flags(introspection=False):
        with logbook.TestHandler() as h:
            logger.warn("Testing")
            assert h.records[0].frame is None
            assert h.records[0].calling_frame is None
            assert h.records[0].module is None