Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing interpreters now error the session on CI by default #567

Merged
merged 7 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,16 @@ If the Noxfile sets ``nox.options.stop_on_first_error``, you can override the No
Failing sessions when the interpreter is missing
------------------------------------------------

By default, Nox will skip sessions where the Python interpreter can't be found. If you want Nox to mark these sessions as failed, you can use ``--error-on-missing-interpreters``:
By default, when not on CI, Nox will skip sessions where the Python interpreter can't be found. If you want Nox to mark these sessions as failed, you can use ``--error-on-missing-interpreters``:

.. code-block:: console

nox --error-on-missing-interpreters

If the Noxfile sets ``nox.options.error_on_missing_interpreters``, you can override the Noxfile setting from the command line by using ``--no-error-on-missing-interpreters``.

If being run on Continuous Integration (CI) systems, Nox will treat missing interpreters as errors by default to avoid sessions silently passing when the requested python interpreter is not installed. Nox does this by looking for an environment variable called ``CI`` which is a convention used by most CI providers.

.. _opt-error-on-external-run:

Disallowing external programs
Expand Down
2 changes: 2 additions & 0 deletions nox/_option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def make_flag_pair(
name: str,
enable_flags: tuple[str, str] | tuple[str],
disable_flags: tuple[str],
default: bool = False,
cjolowicz marked this conversation as resolved.
Show resolved Hide resolved
**kwargs: Any,
) -> tuple[Option, Option]:
"""Returns two options - one to enable a behavior and another to disable it.
Expand All @@ -172,6 +173,7 @@ def make_flag_pair(
*enable_flags,
noxfile=True,
merge_func=functools.partial(flag_pair_merge_func, name, disable_name),
default=default,
cjolowicz marked this conversation as resolved.
Show resolved Hide resolved
**kwargs,
)

Expand Down
1 change: 1 addition & 0 deletions nox/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def _session_completer(
("--no-error-on-missing-interpreters",),
group=options.groups["execution"],
help="Error instead of skipping sessions if an interpreter can not be located.",
default=True if "CI" in os.environ else False,
FollowTheProcess marked this conversation as resolved.
Show resolved Hide resolved
),
*_option_set.make_flag_pair(
"error_on_external_run",
Expand Down
3 changes: 3 additions & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,9 @@ def execute(self) -> Result:
if self.global_config.error_on_missing_interpreters:
return Result(self, Status.FAILED, reason=str(exc))
else:
logger.warning(
"Missing interpreters will error by default on CI systems."
)
return Result(self, Status.SKIPPED, reason=str(exc))

except _SessionQuit as exc:
Expand Down
21 changes: 19 additions & 2 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def make_runner(self):
envdir="envdir",
posargs=[],
reuse_existing_virtualenvs=False,
error_on_missing_interpreters=False,
error_on_missing_interpreters=True if "CI" in os.environ else False,
FollowTheProcess marked this conversation as resolved.
Show resolved Hide resolved
),
manifest=mock.create_autospec(nox.manifest.Manifest),
)
Expand Down Expand Up @@ -904,14 +904,31 @@ def test_execute_with_manifest_null_session_func(self):
assert result.status == nox.sessions.Status.SKIPPED
assert "no parameters" in result.reason

def test_execute_skip_missing_interpreter(self):
def test_execute_skip_missing_interpreter(self, caplog, monkeypatch):
# Important to have this first here as the runner will pick it up
# to set default for --error-on-missing-interpreters
monkeypatch.delenv("CI", raising=False)

runner = self.make_runner_with_mock_venv()
runner._create_venv.side_effect = nox.virtualenv.InterpreterNotFound("meep")

result = runner.execute()

assert result.status == nox.sessions.Status.SKIPPED
assert "meep" in result.reason
assert (
"Missing interpreters will error by default on CI systems." in caplog.text
)

def test_execute_missing_interpreter_on_CI(self, monkeypatch):
monkeypatch.setenv("CI", "True")
runner = self.make_runner_with_mock_venv()
runner._create_venv.side_effect = nox.virtualenv.InterpreterNotFound("meep")

result = runner.execute()

assert result.status == nox.sessions.Status.FAILED
assert "meep" in result.reason

def test_execute_error_missing_interpreter(self):
runner = self.make_runner_with_mock_venv()
Expand Down