From 931e4632ce27a2a7a6fd44e706c2b903d13d767f Mon Sep 17 00:00:00 2001 From: jeanluc Date: Thu, 24 Oct 2024 14:16:22 +0200 Subject: [PATCH] Add test for issue #66996 --- .../functional/modules/state/test_state.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/pytests/functional/modules/state/test_state.py b/tests/pytests/functional/modules/state/test_state.py index e5e104ffcca..c9d188d3b36 100644 --- a/tests/pytests/functional/modules/state/test_state.py +++ b/tests/pytests/functional/modules/state/test_state.py @@ -3,6 +3,7 @@ import os import textwrap import threading import time +from textwrap import dedent import pytest @@ -1081,3 +1082,47 @@ def test_state_sls_mock_ret(state_tree): ret["cmd_|-echo1_|-echo 'This is a test!'_|-run"]["comment"] == "Not called, mocked" ) + + +@pytest.fixture +def _state_requires_env(loaders, state_tree): + mod_contents = dedent( + r""" + def test_it(name): + return { + "name": name, + "result": __env__ == "base", + "comment": "", + "changes": {}, + } + """ + ) + sls = "test_spawning" + sls_contents = dedent( + """ + This should not fail on spawning platforms: + requires_env.test_it: + - name: foo + - parallel: true + """ + ) + with pytest.helpers.temp_file( + f"{sls}.sls", sls_contents, state_tree + ), pytest.helpers.temp_file("_states/requires_env.py", mod_contents, state_tree): + res = loaders.modules.saltutil.sync_states() + assert "states.requires_env" in res + yield sls + + +def test_state_apply_parallel_spawning_with_global_dunders(state, _state_requires_env): + """ + Ensure state modules called via `parallel: true` have access to injected + global dunders like `__env__`. + """ + ret = state.apply(_state_requires_env) + assert ( + ret[ + "requires_env_|-This should not fail on spawning platforms_|-foo_|-test_it" + ]["result"] + is True + )