Skip to content

Commit

Permalink
Don't rely on monkeypatching for find caller test
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Sep 19, 2023
1 parent 575e2a4 commit d8aebf9
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions tests/test_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,17 @@ def test_no_stack_info_by_default(self):

assert None is stack_info

def test_find_caller(self, monkeypatch):
def test_find_caller(self, caplog):
"""
The caller is found.
"""
logger = LoggerFactory()()
log_handle = call_recorder(lambda x: None)
monkeypatch.setattr(logger, "handle", log_handle)

logger.error("Test")

log_record = log_handle.calls[0].args[0]

assert log_record.funcName == "test_find_caller"
assert log_record.name == __name__
assert log_record.filename == os.path.basename(__file__)
assert caplog.text.startswith(
"ERROR tests.test_stdlib:test_stdlib.py"
)

def test_sets_correct_logger(self):
"""
Expand Down

0 comments on commit d8aebf9

Please sign in to comment.