Skip to content

Commit

Permalink
Pass environment in testinfra (#4014)
Browse files Browse the repository at this point in the history
Related to #4011

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
zhan9san and pre-commit-ci[bot] authored Aug 16, 2023
1 parent 626d784 commit 33e5d8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}

env:
PYTEST_REQPASS: 449
PYTEST_REQPASS: 450
steps:
- uses: actions/checkout@v3
with:
Expand Down
12 changes: 12 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,18 @@ 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 33e5d8b

Please sign in to comment.