Improved test logging with frame inspection
This commit is contained in:
@@ -6,6 +6,16 @@ import sys
|
|||||||
import shlex
|
import shlex
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
import inspect
|
||||||
|
|
||||||
|
def get_caller() -> str:
|
||||||
|
frame = inspect.currentframe()
|
||||||
|
caller_frame = frame.f_back.f_back
|
||||||
|
frame_info = inspect.getframeinfo(caller_frame)
|
||||||
|
ret = f"{frame_info.filename}:{frame_info.lineno}::{frame_info.function}"
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class Cli:
|
class Cli:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.parser = create_parser(prog="clan")
|
self.parser = create_parser(prog="clan")
|
||||||
@@ -13,6 +23,7 @@ class Cli:
|
|||||||
def run(self, args: list[str]) -> argparse.Namespace:
|
def run(self, args: list[str]) -> argparse.Namespace:
|
||||||
cmd = shlex.join(["clan"] + args)
|
cmd = shlex.join(["clan"] + args)
|
||||||
log.debug(f"Command: {cmd}")
|
log.debug(f"Command: {cmd}")
|
||||||
|
log.debug(f"Caller {get_caller()}")
|
||||||
parsed = self.parser.parse_args(args)
|
parsed = self.parser.parse_args(args)
|
||||||
if hasattr(parsed, "func"):
|
if hasattr(parsed, "func"):
|
||||||
parsed.func(parsed)
|
parsed.func(parsed)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ def _test_identities(
|
|||||||
cli = Cli()
|
cli = Cli()
|
||||||
sops_folder = test_flake.path / "sops"
|
sops_folder = test_flake.path / "sops"
|
||||||
|
|
||||||
cli.run(["secrets", what, "add", "foo", age_keys[0].pubkey])
|
cli.run(["secrets", what, "add", "foo", age_keys[0].pubkey, test_flake.name])
|
||||||
assert (sops_folder / what / "foo" / "key.json").exists()
|
assert (sops_folder / what / "foo" / "key.json").exists()
|
||||||
with pytest.raises(ClanError):
|
with pytest.raises(ClanError):
|
||||||
cli.run(["secrets", what, "add", "foo", age_keys[0].pubkey])
|
cli.run(["secrets", what, "add", "foo", age_keys[0].pubkey])
|
||||||
|
|||||||
Reference in New Issue
Block a user