-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test "getframe_fallback" separately and not against all unit tests
- Loading branch information
Showing
3 changed files
with
34 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import sys | ||
|
||
import pytest | ||
import loguru | ||
|
||
def test_with_get_frame(monkeypatch): | ||
def test_with_sys_getframe(monkeypatch): | ||
patched = lambda: None | ||
monkeypatch.setattr(sys, '_getframe', patched) | ||
assert loguru.get_get_frame_function() == patched | ||
assert loguru.get_getframe_function() == patched | ||
|
||
def test_without_get_frame(monkeypatch): | ||
def test_without_sys_getframe(monkeypatch): | ||
monkeypatch.delattr(sys, '_getframe') | ||
assert loguru.get_get_frame_function() == loguru.get_frame_fallback | ||
assert loguru.get_getframe_function() == loguru.getframe_fallback | ||
|
||
def test_getframe_fallback(): | ||
frame_root = frame_a = frame_b = None | ||
|
||
def a(): | ||
nonlocal frame_a | ||
frame_a = loguru.getframe_fallback(1) | ||
b() | ||
|
||
def b(): | ||
nonlocal frame_b | ||
frame_b = loguru.getframe_fallback(2) | ||
|
||
frame_root = loguru.getframe_fallback(0) | ||
a() | ||
|
||
assert frame_a == frame_b == frame_root | ||
|