Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ The following options can be specified in the Noxfile:
* ``nox.options.error_on_missing_interpreters`` is equivalent to specifying :ref:`--error-on-missing-interpreters <opt-error-on-missing-interpreters>`. You can force this off by specifying ``--no-error-on-missing-interpreters`` during invocation.
* ``nox.options.error_on_external_run`` is equivalent to specifying :ref:`--error-on-external-run <opt-error-on-external-run>`. You can force this off by specifying ``--no-error-on-external-run`` during invocation.
* ``nox.options.report`` is equivalent to specifying :ref:`--report <opt-report>`.
* ``nox.options.verbose`` is equivalent to specifying :ref:`-v or --verbose <opt-verbose>`. You can force this off by specifying ``--no-verbose`` during invocation.


When invoking ``nox``, any options specified on the command line take precedence over the options specified in the Noxfile. If either ``--sessions`` or ``--keywords`` is specified on the command line, *both* options specified in the Noxfile will be ignored.
Expand Down
8 changes: 6 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,18 @@ However, this will never output colorful logs:
nox --nocolor


.. _opt-report:
.. _opt-verbose:


Controlling commands verbosity
------------------------------

By default, Nox will only show output of commands that fail, or, when the commands get passed ``silent=False``.
By passing ``--verbose`` to Nox, all output of all commands run is shown, regardless of the silent argument.
By either passing ``--verbose`` to Nox or setting ``nox.options.verbose = True``, all output of all commands
run is shown, regardless of the silent argument.


.. _opt-report:


Outputting a machine-readable report
Expand Down
9 changes: 3 additions & 6 deletions nox/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,12 @@ def _tag_completer(
help="Arguments following ``--`` that are passed through to the session(s).",
finalizer_func=_posargs_finalizer,
),
_option_set.Option(
*_option_set.make_flag_pair(
"verbose",
"-v",
"--verbose",
("-v", "--verbose"),
("--no-verbose",),
group=options.groups["reporting"],
action="store_true",
default=False,
help="Logs the output of all commands run including commands marked silent.",
noxfile=True,
),
_option_set.Option(
"add_timestamp",
Expand Down
4 changes: 2 additions & 2 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def conda_install(
args = _dblquote_pkg_install_args(args)

if silent is None:
silent = True
silent = not self._runner.global_config.verbose

extraopts: list[str] = []
if auto_offline and venv.is_offline():
Expand Down Expand Up @@ -838,7 +838,7 @@ def install(
return

if silent is None:
silent = True
silent = not self._runner.global_config.verbose

if isinstance(venv, VirtualEnv) and venv.venv_backend == "uv":
cmd = ["uv", "pip", "install"]
Expand Down
74 changes: 74 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,80 @@ class SessionNoSlots(nox.sessions.Session):
):
session.install("requests", "urllib3")

@pytest.mark.parametrize(
("verbose", "expected_silent"),
[
(True, False),
(False, True),
],
)
def test_install_verbose(self, verbose: bool, expected_silent: bool) -> None:
runner = nox.sessions.SessionRunner(
name="test",
signatures=["test"],
func=mock.sentinel.func,
global_config=_options.options.namespace(posargs=[], verbose=verbose),
manifest=mock.create_autospec(nox.manifest.Manifest),
)
runner.venv = make_fake_env()

class SessionNoSlots(nox.sessions.Session):
pass

session = SessionNoSlots(runner=runner)

with mock.patch.object(session, "_run", autospec=True) as run:
session.install("requests", "urllib3")
run.assert_called_once_with(
"python",
"-m",
"pip",
"install",
"requests",
"urllib3",
**_run_with_defaults(silent=expected_silent, external="error"),
)

@pytest.mark.parametrize(
("verbose", "expected_silent"),
[
(True, False),
(False, True),
],
)
def test_conda_install_verbose(self, verbose: bool, expected_silent: bool) -> None:
runner = nox.sessions.SessionRunner(
name="test",
signatures=["test"],
func=mock.sentinel.func,
global_config=_options.options.namespace(posargs=[], verbose=verbose),
manifest=mock.create_autospec(nox.manifest.Manifest),
)
runner.venv = mock.create_autospec(nox.virtualenv.CondaEnv)
assert runner.venv
runner.venv.location = "/path/to/conda/env"
runner.venv.env = {}
runner.venv.is_offline = lambda: False # type: ignore[attr-defined]
runner.venv.conda_cmd = "conda" # type: ignore[attr-defined]

class SessionNoSlots(nox.sessions.Session):
pass

session = SessionNoSlots(runner=runner)

with mock.patch.object(session, "_run", autospec=True) as run:
session.conda_install("requests", "urllib3")
run.assert_called_once_with(
"conda",
"install",
"--yes",
"--prefix",
"/path/to/conda/env",
"requests",
"urllib3",
**_run_with_defaults(silent=expected_silent, external="error"),
)

def test_notify(self) -> None:
session, runner = self.make_session_and_runner()

Expand Down
Loading