1717 from pathlib import Path
1818
1919
20- ARGS = Namespace (
21- isolation_mode = "cfg" ,
22- log_append = False ,
23- log_file = "/dev/null" ,
24- log_level = "warning" ,
25- verbose = 0 ,
26- )
27-
28-
2920@pytest .fixture (name = "cli" )
3021def init_cli (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> Cli :
3122 """Fixture to mock the CLI for testing.
@@ -47,8 +38,16 @@ def init_cli(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Cli:
4738 monkeypatch .chdir (cwd )
4839 monkeypatch .delenv ("ANSIBLE_CONFIG" , raising = False )
4940
41+ args = Namespace (
42+ isolation_mode = "cfg" ,
43+ log_append = False ,
44+ log_file = "/dev/null" ,
45+ log_level = "warning" ,
46+ verbose = 0 ,
47+ )
48+
5049 cli = Cli ()
51- cli .args = ARGS
50+ cli .args = args
5251 cli .acfg_cwd = AnsibleCfg (path = cwd / "ansible.cfg" )
5352 cli .acfg_home = AnsibleCfg (path = home / "ansible.cfg" )
5453 cli .acfg_system = AnsibleCfg (path = system / "ansible.cfg" )
@@ -123,6 +122,9 @@ def test_acfg_home_modified(cli: Cli) -> None:
123122 assert cli .isolation_check () is True
124123 assert test_path .read_text () == expected
125124 assert cli .acfg_trusted == test_path
125+ stat = cli .acfg_trusted .stat ().st_mtime
126+ assert cli .isolation_check () is True
127+ assert cli .acfg_trusted .stat ().st_mtime == stat
126128
127129
128130def test_acfg_system_ok (cli : Cli ) -> None :
@@ -162,21 +164,14 @@ def test_invalid_isolation_mode(cli: Cli) -> None:
162164 assert cli .acfg_trusted is None
163165
164166
165- def test_isolation_cfg_with_env_var (
166- monkeypatch : pytest .MonkeyPatch ,
167- tmp_path : Path ,
168- ) -> None :
167+ def test_isolation_cfg_with_env_var (cli : Cli , monkeypatch : pytest .MonkeyPatch ) -> None :
169168 """Test isolation_cfg method with ANSIBLE_CONFIG environment variable.
170169
171170 Args:
171+ cli: A Cli instance from a fixture
172172 monkeypatch: Pytest fixture for monkey patching.
173- tmp_path: Pytest fixture for temporary file paths.
174173 """
175- cli = Cli ()
176- cli .args = ARGS
177- cli .init_output ()
178-
179- monkeypatch .setenv ("ANSIBLE_CONFIG" , str (tmp_path / "ansible.cfg" ))
174+ monkeypatch .setenv ("ANSIBLE_CONFIG" , str (cli .acfg_cwd .path ))
180175
181176 assert cli .isolation_check () is False
182177 assert cli .acfg_trusted is None
0 commit comments