|
9 | 9 |
|
10 | 10 | from pretend import stub
|
11 | 11 |
|
12 |
| -import structlog._frames |
13 |
| - |
14 | 12 | from structlog._frames import (
|
15 | 13 | _find_first_app_frame_and_name,
|
16 | 14 | _format_exception,
|
|
19 | 17 |
|
20 | 18 |
|
21 | 19 | class TestFindFirstAppFrameAndName:
|
22 |
| - def test_ignores_structlog_by_default(self, monkeypatch): |
| 20 | + def test_ignores_structlog_by_default(self): |
23 | 21 | """
|
24 | 22 | No matter what you pass in, structlog frames get always ignored.
|
25 | 23 | """
|
26 | 24 | f1 = stub(f_globals={"__name__": "test"}, f_back=None)
|
27 | 25 | f2 = stub(f_globals={"__name__": "structlog.blubb"}, f_back=f1)
|
28 |
| - monkeypatch.setattr(structlog._frames.sys, "_getframe", lambda: f2) |
29 |
| - f, n = _find_first_app_frame_and_name() |
| 26 | + |
| 27 | + f, n = _find_first_app_frame_and_name(_getframe=lambda: f2) |
30 | 28 |
|
31 | 29 | assert (f1, "test") == (f, n)
|
32 | 30 |
|
33 |
| - def test_ignoring_of_additional_frame_names_works(self, monkeypatch): |
| 31 | + def test_ignoring_of_additional_frame_names_works(self): |
34 | 32 | """
|
35 | 33 | Additional names are properly ignored too.
|
36 | 34 | """
|
37 | 35 | f1 = stub(f_globals={"__name__": "test"}, f_back=None)
|
38 | 36 | f2 = stub(f_globals={"__name__": "ignored.bar"}, f_back=f1)
|
39 | 37 | f3 = stub(f_globals={"__name__": "structlog.blubb"}, f_back=f2)
|
40 |
| - monkeypatch.setattr(structlog._frames.sys, "_getframe", lambda: f3) |
41 |
| - f, n = _find_first_app_frame_and_name(additional_ignores=["ignored"]) |
| 38 | + |
| 39 | + f, n = _find_first_app_frame_and_name( |
| 40 | + additional_ignores=["ignored"], _getframe=lambda: f3 |
| 41 | + ) |
42 | 42 |
|
43 | 43 | assert (f1, "test") == (f, n)
|
44 | 44 |
|
45 |
| - def test_tolerates_missing_name(self, monkeypatch): |
| 45 | + def test_tolerates_missing_name(self): |
46 | 46 | """
|
47 | 47 | Use ``?`` if `f_globals` lacks a `__name__` key
|
48 | 48 | """
|
49 | 49 | f1 = stub(f_globals={}, f_back=None)
|
50 |
| - monkeypatch.setattr(structlog._frames.sys, "_getframe", lambda: f1) |
51 |
| - f, n = _find_first_app_frame_and_name() |
| 50 | + |
| 51 | + f, n = _find_first_app_frame_and_name(_getframe=lambda: f1) |
52 | 52 |
|
53 | 53 | assert (f1, "?") == (f, n)
|
54 | 54 |
|
55 |
| - def test_tolerates_name_explicitly_None_oneframe(self, monkeypatch): |
| 55 | + def test_tolerates_name_explicitly_None_oneframe(self): |
56 | 56 | """
|
57 | 57 | Use ``?`` if `f_globals` has a `None` valued `__name__` key
|
58 | 58 | """
|
59 | 59 | f1 = stub(f_globals={"__name__": None}, f_back=None)
|
60 |
| - monkeypatch.setattr(structlog._frames.sys, "_getframe", lambda: f1) |
61 |
| - f, n = _find_first_app_frame_and_name() |
| 60 | + |
| 61 | + f, n = _find_first_app_frame_and_name(_getframe=lambda: f1) |
62 | 62 |
|
63 | 63 | assert (f1, "?") == (f, n)
|
64 | 64 |
|
65 |
| - def test_tolerates_name_explicitly_None_manyframe(self, monkeypatch): |
| 65 | + def test_tolerates_name_explicitly_None_manyframe(self): |
66 | 66 | """
|
67 | 67 | Use ``?`` if `f_globals` has a `None` valued `__name__` key,
|
68 | 68 | multiple frames up.
|
69 | 69 | """
|
70 | 70 | f1 = stub(f_globals={"__name__": None}, f_back=None)
|
71 | 71 | f2 = stub(f_globals={"__name__": "structlog.blubb"}, f_back=f1)
|
72 |
| - monkeypatch.setattr(structlog._frames.sys, "_getframe", lambda: f2) |
73 |
| - f, n = _find_first_app_frame_and_name() |
| 72 | + f, n = _find_first_app_frame_and_name(_getframe=lambda: f2) |
74 | 73 |
|
75 | 74 | assert (f1, "?") == (f, n)
|
76 | 75 |
|
77 |
| - def test_tolerates_f_back_is_None(self, monkeypatch): |
| 76 | + def test_tolerates_f_back_is_None(self): |
78 | 77 | """
|
79 | 78 | Use ``?`` if all frames are in ignored frames.
|
80 | 79 | """
|
81 | 80 | f1 = stub(f_globals={"__name__": "structlog"}, f_back=None)
|
82 |
| - monkeypatch.setattr(structlog._frames.sys, "_getframe", lambda: f1) |
83 |
| - f, n = _find_first_app_frame_and_name() |
| 81 | + |
| 82 | + f, n = _find_first_app_frame_and_name(_getframe=lambda: f1) |
84 | 83 |
|
85 | 84 | assert (f1, "?") == (f, n)
|
86 | 85 |
|
|
0 commit comments