diff --git a/src/pickley/cli.py b/src/pickley/cli.py index e378bc4..23cf0d5 100644 --- a/src/pickley/cli.py +++ b/src/pickley/cli.py @@ -88,6 +88,9 @@ def _locked_by(self): if not runez.check_pid(pid): return None # PID is no longer active + if pid is not None: + return "-no args-" # Holder is alive, but was invoked without CLI args (so there's no 2nd line) + def __enter__(self): """Acquire lock""" if self.lock_path: diff --git a/tests/test_describe.py b/tests/test_describe.py index c3bcc22..7339766 100644 --- a/tests/test_describe.py +++ b/tests/test_describe.py @@ -11,10 +11,10 @@ def test_describe(cli, monkeypatch): runez.write(".pk/config.json", '{"bake_time": 300, "pinned": {"cowsay": {"python": "3.999"}}}', logger=None) cli.run("-vv describe mgit==1.3.0") assert cli.succeeded - assert " -vv describe " in cli.logged.stdout - assert "pip show mgit" in cli.logged.stdout + assert " -vv describe " in cli.logged + assert "pip show mgit" in cli.logged assert "mgit: version 1.3.0" in cli.logged.stdout - assert "Applying bake_time of 5 minutes" in cli.logged.stdout + assert "Applying bake_time of 5 minutes" in cli.logged cli.run("-vv describe cowsay") assert cli.failed diff --git a/tests/test_ops.py b/tests/test_ops.py index 241c897..722e872 100644 --- a/tests/test_ops.py +++ b/tests/test_ops.py @@ -22,7 +22,7 @@ def test_base(cli, monkeypatch): cli.run("-n base foo") assert cli.failed - assert "Can't find 'foo', try:" in cli.logged.stdout + assert "Can't find 'foo', try:" in cli.logged monkeypatch.delenv("PICKLEY_ROOT") assert find_base("/foo/.venv/bin/pickley") == CFG.resolved_path("/foo/.venv/dev_mode") @@ -365,13 +365,16 @@ def test_lock(temp_cfg, monkeypatch): with pytest.raises(SystemExit): runez.abort("oops") - with SoftLock("foo", give_up=600) as lock: - assert str(lock) == "lock foo" - assert os.path.exists(lock_path) - with pytest.raises(SoftLockException, match="giving up"): - # Try to grab same lock a seconds time, give up after 1 second - with SoftLock("foo", give_up=1, invalid=600): - raise AssertionError("should not be reached") # pragma: no cover + # Lock holder is reported with the CLI args it was invoked with (if any) + for argv, holder in ((["pickley", "install", "foo"], "install foo"), (["pickley"], "-no args-")): + monkeypatch.setattr(sys, "argv", argv) + with SoftLock("foo", give_up=600) as lock: + assert str(lock) == "lock foo" + assert os.path.exists(lock_path) + with pytest.raises(SoftLockException, match=f"giving up\nIt is being held by: pickley .*{holder}"): + # Try to grab same lock a seconds time, give up after 1 second + with SoftLock("foo", give_up=1, invalid=600): + raise AssertionError("should not be reached") # pragma: no cover assert not os.path.exists(lock_path) # Check that lock was released