From 59e5dea59743aa794e8f9f8a53bc550ced577e8a Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 6 Apr 2026 16:13:49 +0200 Subject: [PATCH] fix: make "cmdeploy test --config ..." work, without requiring or implicitely falling back to a "chatmail.ini" in parent dirs --- cmdeploy/src/cmdeploy/cmdeploy.py | 1 + cmdeploy/src/cmdeploy/tests/plugin.py | 5 +++++ cmdeploy/src/cmdeploy/tests/test_cmdeploy.py | 12 ++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index 51ccd3f4..52c7de0d 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -209,6 +209,7 @@ def test_cmd(args, out): """Run local and online tests for chatmail deployment.""" env = os.environ.copy() + env["CHATMAIL_INI"] = str(args.inipath.absolute()) if args.ssh_host: env["CHATMAIL_SSH"] = args.ssh_host diff --git a/cmdeploy/src/cmdeploy/tests/plugin.py b/cmdeploy/src/cmdeploy/tests/plugin.py index 8e8c57d1..269aa828 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -35,6 +35,11 @@ def pytest_runtest_setup(item): def _get_chatmail_config(): + inipath = os.environ.get("CHATMAIL_INI") + if inipath: + path = Path(inipath).resolve() + return read_config(path), path + current = Path().resolve() while 1: path = current.joinpath("chatmail.ini").resolve() diff --git a/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py b/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py index 6e87b4ea..b7f7b873 100644 --- a/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py +++ b/cmdeploy/src/cmdeploy/tests/test_cmdeploy.py @@ -23,15 +23,19 @@ class TestCmdline: run = parser.parse_args(["run"]) assert init and run - def test_init_not_overwrite(self, capsys): - assert main(["init", "chat.example.org"]) == 0 + def test_init_not_overwrite(self, capsys, tmp_path, monkeypatch): + monkeypatch.delenv("CHATMAIL_INI", raising=False) + inipath = tmp_path / "chatmail.ini" + args = ["init", "--config", str(inipath), "chat.example.org"] + assert main(args) == 0 capsys.readouterr() - assert main(["init", "chat.example.org"]) == 1 + assert main(args) == 1 out, err = capsys.readouterr() assert "path exists" in out.lower() - assert main(["init", "chat.example.org", "--force"]) == 0 + args.insert(1, "--force") + assert main(args) == 0 out, err = capsys.readouterr() assert "deleting config file" in out.lower()