Skip to content

Commit a58fe60

Browse files
authored
fix: support forcing Python on parametrized session (#958)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent aa475d6 commit a58fe60

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

nox/manifest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,11 @@ def make_session(
358358
calls = Call.generate_calls(func, parametrize)
359359
for call in calls:
360360
long_names = []
361-
if not multi:
361+
if not multi or (
362+
self._config.force_pythons and call.python in self._config.extra_pythons
363+
):
362364
long_names.append(f"{name}{call.session_signature}")
365+
363366
if func.python:
364367
long_names.append(f"{name}-{func.python}{call.session_signature}")
365368
# Ensure that specifying session-python will run all parameterizations.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import nox
2+
3+
4+
@nox.session
5+
@nox.parametrize(
6+
["version"],
7+
[["8.1.0"], ["7.5.0"]],
8+
["8.1.0", "7.5.0"],
9+
)
10+
def check_package_files(session: nox.Session, version: str):
11+
pass

tests/test_main.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,31 @@ def test_main_no_venv_error() -> None:
150150
nox.main()
151151

152152

153+
def test_main_param_force_python(monkeypatch: pytest.MonkeyPatch) -> None:
154+
"""
155+
Check that Python can be forced if something is parametrized over other things.
156+
"""
157+
158+
# Check that --no-venv overrides force_venv_backend
159+
monkeypatch.setattr(
160+
sys,
161+
"argv",
162+
[
163+
"nox",
164+
"--noxfile",
165+
os.path.join(RESOURCES, "noxfile_parametrize.py"),
166+
"--sessions",
167+
"check_package_files(7.5.0)",
168+
"--force-python",
169+
".".join(str(v) for v in sys.version_info[:2]),
170+
],
171+
)
172+
173+
with mock.patch("sys.exit") as sys_exit:
174+
nox.main()
175+
sys_exit.assert_called_once_with(0)
176+
177+
153178
def test_main_short_form_args(monkeypatch: pytest.MonkeyPatch) -> None:
154179
monkeypatch.setattr(
155180
sys,

0 commit comments

Comments
 (0)