@@ -19,6 +19,14 @@ def _clear_env_var(monkeypatch: MonkeyPatch) -> None:
1919 monkeypatch .delenv ("TOX_GH_MAJOR_MINOR" , raising = False )
2020
2121
22+ @pytest .fixture
23+ def summary_output_path (monkeypatch : MonkeyPatch , tmp_path : Path ) -> Path :
24+ path = tmp_path / "gh_out"
25+ path .touch ()
26+ monkeypatch .setattr (plugin , "GITHUB_STEP_SUMMARY" , str (path ))
27+ return path
28+
29+
2230def test_gh_not_in_actions (monkeypatch : MonkeyPatch , tox_project : ToxProjectCreator ) -> None :
2331 monkeypatch .delenv ("GITHUB_ACTIONS" , raising = False )
2432 project = tox_project ({"tox.ini" : "[testenv]\n package=skip" })
@@ -54,18 +62,17 @@ def test_gh_toxenv_set(monkeypatch: MonkeyPatch, tox_project: ToxProjectCreator)
5462
5563
5664@pytest .mark .parametrize ("via_env" , [True , False ])
57- def test_gh_ok (monkeypatch : MonkeyPatch , tox_project : ToxProjectCreator , tmp_path : Path , via_env : bool ) -> None :
65+ def test_gh_ok (
66+ monkeypatch : MonkeyPatch , tox_project : ToxProjectCreator , tmp_path : Path , summary_output_path : Path , via_env : bool
67+ ) -> None :
5868 if via_env :
5969 monkeypatch .setenv ("TOX_GH_MAJOR_MINOR" , f"{ sys .version_info .major } .{ sys .version_info .minor } " )
6070 else :
6171 monkeypatch .setenv ("PATH" , "" )
62- step_output_file = tmp_path / "gh_out"
63- step_output_file .touch ()
6472 empty_requirements = tmp_path / "empty.txt"
6573 empty_requirements .touch ()
6674 monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
6775 monkeypatch .delenv ("TOXENV" , raising = False )
68- monkeypatch .setattr (plugin , "GITHUB_STEP_SUMMARY" , str (step_output_file ))
6976 ini = f"""
7077 [testenv]
7178 package = editable
@@ -111,17 +118,14 @@ def test_gh_ok(monkeypatch: MonkeyPatch, tox_project: ToxProjectCreator, tmp_pat
111118 assert "a: OK" in result .out
112119 assert "b: OK" in result .out
113120
114- summary_text = step_output_file .read_text ()
121+ summary_text = summary_output_path .read_text ()
115122 assert ":white_check_mark:: a" in summary_text
116123 assert ":white_check_mark:: b" in summary_text
117124
118125
119- def test_gh_fail (monkeypatch : MonkeyPatch , tox_project : ToxProjectCreator , tmp_path : Path ) -> None :
120- step_output_file = tmp_path / "gh_out"
121- step_output_file .touch ()
126+ def test_gh_fail (monkeypatch : MonkeyPatch , tox_project : ToxProjectCreator , summary_output_path : Path ) -> None :
122127 monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
123128 monkeypatch .delenv ("TOXENV" , raising = False )
124- monkeypatch .setattr (plugin , "GITHUB_STEP_SUMMARY" , str (step_output_file ))
125129 ini = f"""
126130 [testenv]
127131 package = skip
@@ -162,6 +166,45 @@ def test_gh_fail(monkeypatch: MonkeyPatch, tox_project: ToxProjectCreator, tmp_p
162166 assert "a: FAIL code 1" in result .out
163167 assert "b: FAIL code 1" in result .out
164168
165- summary_text = step_output_file .read_text ()
169+ summary_text = summary_output_path .read_text ()
166170 assert ":negative_squared_cross_mark:: a" in summary_text
167171 assert ":negative_squared_cross_mark:: b" in summary_text
172+
173+
174+ def test_gh_single_env_ok (monkeypatch : MonkeyPatch , tox_project : ToxProjectCreator , summary_output_path : Path ) -> None :
175+ monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
176+ monkeypatch .delenv ("TOXENV" , raising = False )
177+ ini = f"""
178+ [testenv]
179+ package = editable
180+ [gh]
181+ python =
182+ { sys .version_info [0 ]} = a
183+ """
184+ project = tox_project ({"tox.ini" : ini })
185+ result = project .run ()
186+ result .assert_success ()
187+
188+ summary_text = summary_output_path .read_text ()
189+ assert len (summary_text ) == 0
190+
191+
192+ def test_gh_single_env_fail (
193+ monkeypatch : MonkeyPatch , tox_project : ToxProjectCreator , summary_output_path : Path
194+ ) -> None :
195+ monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
196+ monkeypatch .delenv ("TOXENV" , raising = False )
197+ ini = f"""
198+ [testenv]
199+ package = skip
200+ commands = python -c exit(1)
201+ [gh]
202+ python =
203+ { sys .version_info [0 ]} = a
204+ """
205+ project = tox_project ({"tox.ini" : ini })
206+ result = project .run ()
207+ result .assert_failed ()
208+
209+ summary_text = summary_output_path .read_text ()
210+ assert len (summary_text ) == 0
0 commit comments