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

Document how session.run fails, and how to handle failures #533

Merged
merged 3 commits into from Dec 26, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions nox/sessions.py
Expand Up @@ -262,6 +262,18 @@ def run(

session.run('cmd', '/c', 'del', 'docs/modules.rst')

If ``session.run`` fails, it will stop the session and will not run the next steps.
Basically, this will raise a Python exception. Taking this in count, you can use a
``try...finally`` block for cleanup runs, that will run even if the other runs fail::

try:
session.run("git", "stash", "-k", "-u")
session.run("isort", "--check-only", "--profile=black", ".")
session.run("black", "--check", ".")
session.run("mypy", "--strict", ".")
finally:
session.run("git", "stash", "pop")

:param env: A dictionary of environment variables to expose to the
command. By default, all environment variables are passed.
:type env: dict or None
Expand Down