Skip to content

Commit

Permalink
Add session.warn to output warnings (#482)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
DiddiLeija authored Sep 21, 2021
1 parent e7d4f5a commit 7f63350
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7f63350

Please sign in to comment.