From 272cb25808ea6e92afac3236102f68f8db83fbda Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Fri, 13 Nov 2020 21:10:36 +0100 Subject: [PATCH] Add test case for using --pythons with nox.options.sessions --- tests/test_main.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index 6bb94392..56469a96 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -469,6 +469,37 @@ def generate_noxfile(default_session, default_python, alternate_python): return generate_noxfile +python_current_version = "{}.{}".format(sys.version_info.major, sys.version_info.minor) +python_next_version = "{}.{}".format(sys.version_info.major, sys.version_info.minor + 1) + + +def test_main_noxfile_options_with_pythons_override( + capsys, monkeypatch, generate_noxfile_options_pythons +): + noxfile = generate_noxfile_options_pythons( + default_session="test", + default_python=python_next_version, + alternate_python=python_current_version, + ) + + monkeypatch.setattr( + sys, "argv", ["nox", "--noxfile", noxfile, "--python", python_current_version] + ) + + with mock.patch("sys.exit") as sys_exit: + nox.__main__.main() + _, stderr = capsys.readouterr() + sys_exit.assert_called_once_with(0) + + for python_version in [python_current_version, python_next_version]: + for session in ["test", "launch_rocket"]: + line = "Running session {}-{}".format(session, python_version) + if session == "test" and python_version == python_current_version: + assert line in stderr + else: + assert line not in stderr + + @pytest.mark.parametrize(("isatty_value", "expected"), [(True, True), (False, False)]) def test_main_color_from_isatty(monkeypatch, isatty_value, expected): monkeypatch.setattr(sys, "argv", [sys.executable])