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 runs cause sessions to fail #517

Closed
ktbarrett opened this issue Dec 21, 2021 · 2 comments · Fixed by #533
Closed

Document how runs cause sessions to fail #517

ktbarrett opened this issue Dec 21, 2021 · 2 comments · Fixed by #533

Comments

@ktbarrett
Copy link
Contributor

How would this feature be useful?

I need to always run cleanup code when a task fails. I didn't know how to accomplish that until I realized that sessions fail when session.runs raise CommandFailed. The use of exceptions here means I can cleanup by using a finally block. For example,

@nox.session(reuse_venv=True)
def check(session):
    build_env(session)
    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")

Describe the solution you'd like

Taking the outcome of #516 into account, documenting that this is possible may help other users learn understand what is possible.

@cjolowicz
Copy link
Collaborator

cjolowicz commented Dec 22, 2021

Thanks for catching this! Indeed, the documentation is not explicit about what happens when a command run via session.run fails. This could be a sentence added to the docstring of nox.sessions.Session.run.

I also agree that the pattern of wrapping a try...finally around session.run for cleanup actions is worth mentioning. Not sure about mentioning CommandFailed specifically, as it's currently not part of the public API. Maybe for now it's enough to just say that an exception is raised that causes Nox to mark the session as failed?

@ktbarrett
Copy link
Contributor Author

ktbarrett commented Dec 23, 2021

Also, maybe I missed it, but I never saw it mentioned anywhere that session.run fails the current session immediately.

session.run causes the current session to fail immediately
all sessions listed are always run
if any session fails, the nox invocation fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants