From 7f63350ca4c896a77fffeeca40690fb869a8283d Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 21 Sep 2021 13:34:51 -0500 Subject: [PATCH] Add `session.warn` to output warnings (#482) * Add `session.warn` to output warnings Show warnings during the session. * Update test_sessions.py Add a test for "session.warn" (It is pretty similar to "test_log", but it has changed the logging level to be tested). * Update test_sessions.py Run black to fix linting errors. * Update test_sessions.py Remove an additional whiespace. --- nox/sessions.py | 4 ++++ tests/test_sessions.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/nox/sessions.py b/nox/sessions.py index 5d1b35c0..78a02868 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -516,6 +516,10 @@ def log(self, *args: Any, **kwargs: Any) -> None: """Outputs a log during the session.""" logger.info(*args, **kwargs) + def warn(self, *args: Any, **kwargs: Any) -> None: + """Outputs a warning during the session.""" + logger.warning(*args, **kwargs) + def error(self, *args: Any) -> "_typing.NoReturn": """Immediately aborts the session and optionally logs an error.""" raise _SessionQuit(*args) diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 3c949e64..2d66ba92 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -601,6 +601,14 @@ def test_log(self, caplog): assert "meep" in caplog.text + def test_warn(self, caplog): + caplog.set_level(logging.WARNING) + session, _ = self.make_session_and_runner() + + session.warn("meep") + + assert "meep" in caplog.text + def test_error(self, caplog): caplog.set_level(logging.ERROR) session, _ = self.make_session_and_runner()