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 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
10 changes: 10 additions & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ 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("coverage", "run", "-m", "pytest")
finally:
# Display coverage report even when tests fail.
session.run("coverage", "report")

: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