-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
continue on error #516
Comments
Perhaps something like the following? @nox.session(reuse_venv=True)
def check(session):
build_env(session)
session.run("git", "stash", "-k", "-u")
session.try_run("isort", "--check-only", "--profile=black", ".")
session.try_run("black", "--check", ".")
session.try_run("mypy", "--strict", ".")
session.run("git", "stash", "pop") EDIT: improved example |
Have you considered running the checks in separate Nox sessions? By default, Nox will then run all checks and report failure if any check fails. I'd probably leave the git integration to pre-commit, as a mature solution for this kind of thing. As discussed in #515, a common setup is to invoke pre-commit from Nox. You could then use a standard pre-commit configuration with isort and black. As for mypy, I prefer to run this as a dedicated Nox session, because that makes it easy to install my package and dependencies, allowing mypy to import their types. (Plus I can easily typecheck on multiple Python versions.) |
That makes it kind of obnoxious to run them all from the command line. First, you can't use the argument syntax, since it doesn't support multiple sessions, you have to use the environment variable syntax. Second you have to remember all the checks you want to run. Not having to do that is one of the advantages of using nox. I suppose I could run nox recursively to work-around doing that, but that sounds obnoxious as well. |
I'm not sure I understand what you mean by "argument syntax" and "environment variable syntax", can you clarify? FWIW, you can specify multiple sessions like this:
If you want to run all the sessions defined in noxfile.py, you can invoke nox.options.sessions = ["lint", "mypy"]
I don't think that's necessary given the options mentioned above. |
Yet another option would be to have a wrapper session using import nox
def lint(session): ...
def mypy(session): ...
def check(session):
session.notify("lint")
session.notify("mypy") I'd go for the simpler solutions listed above, unless you need added flexibility (e.g. multiple wrapper sessions). |
After looking for it I found it here. I'm not about to scour the documentation, but I don't remember seeing any other examples except the second line in the first example I linked (that I missed) and its not explicitly stated. Could be clearer.
Not a good solution. "Include everything, but not this stuff" smells funny. It also means there is only one "set" possible.
Perfect! Will use this. However, this isn't mentioned in the tutorial and buried in pages of API documentation. Feel free to close this. I just missed an existing feature that should work for me. |
Closing this, thanks for the feedback! Do feel free to submit any improvements to the docs. For example, the tutorial mentions |
The One idea is to allow @nox.session(python=False)
def check(session):
session.notify(["lint", "mypy"], [lint_posargs, mypy_posargs], asap=True) I admit, this is still not very elegant. A minor aside:
@nox.session
def require_1(session): ...
@nox.session
def require_2(session): ...
@nox.session(python=False)
def dependent(session):
# notify in reverse order since we are appending items to the left of the session queue
session.notify("dependent_helper", asap=True)
session.notify("require_2", asap=True)
session.notify("require_1", asap=True)
@nox.session
def dependent_helper(session):
# The user shouldn't run this session directly. Unfortunately it will still show in
#`nox -l`.
# If run via `dependent`, `require_1` and `require_2` will run before this.
... |
It's also worth noting that if specifying prerequisites gets implemented for #453, this issue would easily be solved by @nox.session(python=False, requires=["lint", "mypy"])
def check(session): pass if the requires list was treated as ordered, i.e. where |
How would this feature be useful?
I have nox set up to run checks. If a check fails, then nox immediately fails the session and none of the remaining checks are run.
Describe alternatives you've considered
session.run
'serror_code
s arguments is an expected failure. It's not what i'm looking for. I want the session to fail if one of the checks fails, but I want all the checks to run.You could manually wrap each
session.run
in a try-catch, collect the exceptions while allowing the test to continue, and re-raise one of the exceptions at the end.Describe the solution you'd like
I see that session failure occurs when a
session.run
throws aCommandFailed
, this makes things difficult. What may be possible is to not raise that exception when a test fails, but instead signal the session object through some side channel that the run failed. That should allow the session to continue, but fail overall.The text was updated successfully, but these errors were encountered: