diff --git a/src/molecule/test/unit/command/test_base.py b/src/molecule/test/unit/command/test_base.py index 9f3bcb7a20..1d20848a56 100644 --- a/src/molecule/test/unit/command/test_base.py +++ b/src/molecule/test/unit/command/test_base.py @@ -86,6 +86,18 @@ def _patched_sysexit(mocker): return mocker.patch("molecule.util.sysexit") +@pytest.fixture +def _patched_ci_env(request, monkeypatch): + """Parametrize tests with and without CI env vars.""" + envvars = {"CI": None, "TRAVIS": None, "GITHUB_ACTIONS": None, "GITLAB_CI": None} + envvars.update(request.param) + for envvar, value in envvars.items(): + if value is None: + monkeypatch.delenv(envvar, raising=False) + else: + monkeypatch.setenv(envvar, value) + + def test_config_private_member(_instance): assert isinstance(_instance._config, config.Config) @@ -213,8 +225,17 @@ def test_execute_cmdline_scenarios_exit_nodestroy( assert not _patched_prune.called assert not _patched_sysexit.called - -def test_execute_subcommand(config_instance): +@pytest.mark.parametrize( + "_patched_ci_env", + [ + {}, + {"CI": "true", "TRAVIS": "true"}, + {"CI": "true", "GITHUB_ACTIONS": "true"}, + {"CI": "true", "GITLAB_CI": "true"}, + ], + indirect=True, +) +def test_execute_subcommand(config_instance, _patched_ci_env): # scenario's config.action is mutated in-place for every sequence action, # so make sure that is currently set to the executed action assert config_instance.action != "list"