forked from hynek/structlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
75 lines (51 loc) · 1.46 KB
/
conftest.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the MIT License. See the LICENSE file in the root of this
# repository for complete details.
import logging
import sys
from io import StringIO
import pytest
from structlog._log_levels import _NAME_TO_LEVEL
from structlog.testing import CapturingLogger
try:
import twisted
except ImportError:
twisted = None
LOGGER = logging.getLogger()
@pytest.fixture(autouse=True)
def _ensure_logging_framework_not_altered():
"""
Prevents 'ValueError: I/O operation on closed file.' errors.
"""
before_handlers = list(LOGGER.handlers)
yield
LOGGER.handlers = before_handlers
@pytest.fixture(name="sio")
def _sio():
"""
A new StringIO instance.
"""
return StringIO()
@pytest.fixture
def event_dict():
"""
An example event dictionary with multiple value types w/o the event itself.
"""
class A:
def __repr__(self):
return r"<A(\o/)>"
return {"a": A(), "b": [3, 4], "x": 7, "y": "test", "z": (1, 2)}
@pytest.fixture(
name="stdlib_log_method",
params=[m for m in _NAME_TO_LEVEL if m != "notset"],
)
def _stdlib_log_methods(request):
return request.param
@pytest.fixture(name="cl")
def _cl():
return CapturingLogger()
collect_ignore = []
if sys.version_info[:2] < (3, 7):
collect_ignore.append("tests/test_contextvars.py")
if twisted is None:
collect_ignore.append("tests/test_twisted.py")