Skip to content

Commit

Permalink
Pass environment in testinfra
Browse files Browse the repository at this point in the history
  • Loading branch information
zhan9san committed Aug 16, 2023
1 parent ef63714 commit 60ea73e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/molecule/test/a_unit/verifier/test_testinfra.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ def test_execute_bakes(patched_run_command, _patched_testinfra_get_tests, _insta
assert patched_run_command.call_count == 1


@pytest.mark.parametrize("config_instance", ["_verifier_section_data"], indirect=True)
def test_execute_bakes_env(
patched_run_command, _patched_testinfra_get_tests, inventory_directory, _instance
):
_instance.execute()

assert patched_run_command.call_args[1]["env"]["FOO"] == "bar"


def test_testinfra_executes_catches_and_exits_return_code(
patched_run_command,
_patched_testinfra_get_tests,
Expand Down
7 changes: 6 additions & 1 deletion src/molecule/verifier/testinfra.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ def execute(self, action_args=None):
msg = f"Executing Testinfra tests found in {self.directory}/..."
LOG.info(msg)

result = util.run_command(self._testinfra_command, debug=self._config.debug)
result = util.run_command(
self._testinfra_command,
env=self.env,
debug=self._config.debug,
cwd=self._config.scenario.directory,
)
if result.returncode == 0:
msg = "Verifier completed successfully."
LOG.info(msg)
Expand Down

0 comments on commit 60ea73e

Please sign in to comment.