From 1bd8582144cfc177f5a5264eccf24b1b6a060193 Mon Sep 17 00:00:00 2001 From: Fallon Chen Date: Wed, 17 Mar 2021 22:38:58 +0100 Subject: [PATCH] [cli] Enable job test command to read materialized config file --- cli/src/klio_cli/commands/job/test.py | 17 +++++++++++++--- cli/tests/commands/job/test_test.py | 28 +++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/cli/src/klio_cli/commands/job/test.py b/cli/src/klio_cli/commands/job/test.py index 6c094aae..9030bc16 100644 --- a/cli/src/klio_cli/commands/job/test.py +++ b/cli/src/klio_cli/commands/job/test.py @@ -21,12 +21,23 @@ class TestPipeline(base.BaseDockerizedPipeline): def __init__(self, job_dir, klio_config, docker_runtime_config): super().__init__(job_dir, klio_config, docker_runtime_config) - self.requires_config_file = False + self.requires_config_file = True def _get_environment(self): envs = super()._get_environment() envs["KLIO_TEST_MODE"] = "true" return envs - def _get_command(self, pytest_args): - return ["test"] + pytest_args + def _get_command(self, *args, **kwargs): + return ["test"] + + def _add_pytest_args(self, cmd, pytest_args): + if pytest_args: + cmd.extend(pytest_args) + + def _get_docker_runflags(self, *args, **kwargs): + base_runflags = super()._get_docker_runflags(*args, **kwargs) + # add pytest args *after* the base command flags are added + pytest_args = kwargs.get("pytest_args", []) + self._add_pytest_args(base_runflags["command"], pytest_args) + return base_runflags diff --git a/cli/tests/commands/job/test_test.py b/cli/tests/commands/job/test_test.py index 422299d7..36b43f2c 100644 --- a/cli/tests/commands/job/test_test.py +++ b/cli/tests/commands/job/test_test.py @@ -42,8 +42,32 @@ def test_get_environment(test_pipeline): def test_get_command(test_pipeline): - assert ["test", "py", "args"] == test_pipeline._get_command(["py", "args"]) + assert ["test"] == test_pipeline._get_command() + + +def test_add_pytest_args(test_pipeline): + docker_runflags = {"command": ["cmd"]} + test_pipeline._add_pytest_args(docker_runflags["command"], ["py", "args"]) + assert ["cmd", "py", "args"] == docker_runflags["command"] + + +def test_get_docker_runflags(mocker, monkeypatch, test_pipeline): + mock_base_docker_runflags = mocker.Mock() + mock_base_docker_runflags.return_value = { + "command": ["test", "--config-file", "x"] + } + monkeypatch.setattr( + test_job.base.BaseDockerizedPipeline, + "_get_docker_runflags", + mock_base_docker_runflags, + ) + actual_runflags = test_pipeline._get_docker_runflags( + pytest_args=["py", "args"] + ) + + expected = ["test", "--config-file", "x", "py", "args"] + assert expected == actual_runflags["command"] def test_requires_config_setting(test_pipeline): - assert not test_pipeline.requires_config_file + assert test_pipeline.requires_config_file