Created
April 11, 2022 15:38
-
-
Save kezabelle/eaf852254bd824c9a94c65664676dbbf to your computer and use it in GitHub Desktop.
What test methods (python unittest style) call this? A dirty hack of a snippet for me to re-use as I explore a new project.
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
for frame in inspect.getouterframes(inspect.currentframe()): | |
if frame.function.startswith("test_"): | |
repr = "<unknown>" | |
caller = "" | |
if "self" in frame.frame.f_locals: | |
caller = frame.frame.f_locals["self"] | |
elif "cls" in frame.frame.f_locals: | |
caller = frame.frame.f_locals["cls"] | |
if caller: | |
if not hasattr(caller, "__name__"): | |
repr = f"{caller.__module__}.{caller.__class__.__name__}" | |
else: | |
repr = f"{caller.__module__}.{caller.__qualname__}" | |
print(frame.filename, frame.lineno, f"{repr}.{frame.function}") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment