Improved test logging with frame inspection
This commit is contained in:
parent
8cc1c2c4bd
commit
03cabda2d4
@ -6,6 +6,16 @@ import sys
|
||||
import shlex
|
||||
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:
|
||||
def __init__(self) -> None:
|
||||
self.parser = create_parser(prog="clan")
|
||||
@ -13,6 +23,7 @@ class Cli:
|
||||
def run(self, args: list[str]) -> argparse.Namespace:
|
||||
cmd = shlex.join(["clan"] + args)
|
||||
log.debug(f"Command: {cmd}")
|
||||
log.debug(f"Caller {get_caller()}")
|
||||
parsed = self.parser.parse_args(args)
|
||||
if hasattr(parsed, "func"):
|
||||
parsed.func(parsed)
|
||||
|
@ -25,7 +25,7 @@ def _test_identities(
|
||||
cli = Cli()
|
||||
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()
|
||||
with pytest.raises(ClanError):
|
||||
cli.run(["secrets", what, "add", "foo", age_keys[0].pubkey])
|
||||
|
Loading…
Reference in New Issue
Block a user