Repository: theacodes/nox (python)

Issue:
Expose a `warn` log to the session
**How would this feature be useful?**
<!-- Describe any use cases this solves or frustrations it alleviates.   -->
I often find myself using the `session.log` method in some of my more complex sessions to inform the user
what's going on.

I do use the `session.error` for failing things but occasionally I run into something that would be more suitable as a warning in the yellow text (e.g. warning if things are out of date etc.)

**Describe the solution you'd like**
<!-- If you have an idea of how to do this, write it here! -->
Some way of logging a warning from within a session. This could be either a `session.warn` or maybe a `session.log("message", type="warn")` or something like that.

**Describe alternatives you've considered**
<!-- If there's some workaround or alternative solutions, let us know. -->
As far as I know there's no way of doing this currently (I could be wrong).


Pull request description:
Add `session.warn` to output warnings
Closes #481. Create `session.warn` to show warnings during the session.

cc @theacodes @FollowTheProcess

Patch:
diff --git a/nox/sessions.py b/nox/sessions.py
index 5d1b35c..78a0286 100644
--- a/nox/sessions.py
+++ b/nox/sessions.py
@@ -516,6 +516,10 @@ class Session:
         """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)


Test patch:
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index 3c949e6..2d66ba9 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -601,6 +601,14 @@ class TestSession:
 
         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()