From 3f2eb8432338b0885268ec8ca2876a0e33eded0f Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 11 Dec 2023 12:18:10 +0100 Subject: [PATCH] fix tests and run all tests on "cmdeploy test" --- .../src/deploy_chatmail/cmdeploy.py | 8 +++++-- tests/test_cmdeploy.py | 22 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/deploy-chatmail/src/deploy_chatmail/cmdeploy.py b/deploy-chatmail/src/deploy_chatmail/cmdeploy.py index 2307a968..cf37f28e 100644 --- a/deploy-chatmail/src/deploy_chatmail/cmdeploy.py +++ b/deploy-chatmail/src/deploy_chatmail/cmdeploy.py @@ -125,7 +125,7 @@ def test_cmd(args, out): pytest_path = shutil.which("pytest") proc3 = subprocess.run( - [pytest_path, "tests/online", "-rs", "-x", "-vrx", "--durations=5"] + [pytest_path, "tests/", "-rs", "-x", "-vrx", "--durations=5"] ) if any(x.returncode != 0 for x in (proc1, proc2, proc3)): return 1 @@ -239,7 +239,11 @@ def main(args=None): raise SystemExit(1) try: - sys.exit(args.func(args, out, **kwargs)) + res = args.func(args, out, **kwargs) + if res is None: + res = 0 + return res + except KeyboardInterrupt: out.red("KeyboardInterrupt") sys.exit(130) diff --git a/tests/test_cmdeploy.py b/tests/test_cmdeploy.py index a57933af..cad55bdd 100644 --- a/tests/test_cmdeploy.py +++ b/tests/test_cmdeploy.py @@ -1,25 +1,33 @@ +import os + import pytest from deploy_chatmail.cmdeploy import get_parser, main from chatmaild.config import read_config +@pytest.fixture(autouse=True) +def _chdir(tmp_path): + old = os.getcwd() + os.chdir(tmp_path) + yield + os.chdir(old) + + class TestCmdline: def test_parser(self, capsys): parser = get_parser() parser.parse_args([]) init = parser.parse_args(["init", "chat.example.org"]) - update = parser.parse_args(["install"]) - assert init and update + run = parser.parse_args(["run"]) + assert init and run - def test_init(self, tmpdir): - tmpdir.chdir() + def test_init(self, tmp_path): main(["init", "chat.example.org"]) - inipath = tmpdir.join("chatmail.ini") + inipath = tmp_path.joinpath("chatmail.ini") config = read_config(inipath.strpath) assert config.mailname == "chat.example.org" - def test_init_not_overwrite(self, tmpdir): - tmpdir.chdir() + def test_init_not_overwrite(self): main(["init", "chat.example.org"]) with pytest.raises(SystemExit): main(["init", "chat.example.org"])