-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add --onsigint handler, run on KeyboardInterrupt #46
Conversation
This gets run on KeyboardInterrupt/SIGINT, which could be sent by a `--beforerun` script, which kills all child processes (i.e. any currently running py.test instance). This also introduces the explicit "failed" state, which is not "not passed" with py.test.
My wrapper script: https://github.com/blueyed/dotfiles/blob/master/usr/bin/ptw-watch-tests (Yes, it screams for using It will make use of tmux window title colors. |
btw: exit codes are documented (and importable |
Hmm, py.test also uses interrupted with
This should get handled as a failure.. |
Back to `failed = not passed` also for py.test: py.test also uses interrupted with `-x`: > Interrupted: stopping after 1 failures This should get handled as a failure..
Handle onsigint always
Add --onsigint handler, run on KeyboardInterrupt
@blueyed I'm thinking of releasing the CLI arg under a different name. |
@joeyespo btw: there were some |
@blueyed 😄 |
Awesome. Renamed in 7d9516f. |
os.system(onsigint) | ||
else: | ||
if onexit: | ||
os.system(onexit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Poking around with this today, I noticed with the else
, onexit
will never get called (unless there was a problem with ptw). I think onexit
should always be called regardless, since that's its intention.
Why couldn't you have used onexit
before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why couldn't you have used
onexit
before?
The use case here is to be called when the process is interrupted (and then kill its children / running py.test).
I see that this could be handled better in general, but was the way to go when seeing the existing handlers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since ptw runs indefinitely, the only way onexit
will be called is if the process is interrupted. So would that work for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right probably, and I've been using the other interrupt handler then only (https://github.com/joeyespo/pytest-watch/pull/46/files#diff-298efc967591604e348416060d077075R129).
Feel free to fix / enhance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok cool. Thanks!
I'm currently rewriting some of the logic so that only one instance of py.test gets run at a time. Just wanted to make sure I'm not stepping on your toes with a specific case I didn't know about.
FYI, 4.0 was just published. It contains a slightly more abstract For running code when you interrupt ptw (or your Feel free to open a new issue if this doesn't cover all the bases. |
@joeyespo |
Thanks! What do you mean by "script"? As in An ENV variable seems reasonable. It's self-contained, flexible, can be the first of more, and would be just as much work for a script to access it than a CLI argument. Can you think of any downsides? |
This gets run on KeyboardInterrupt/SIGINT, which could be sent by a
--beforerun
script, which kills all child processes (i.e. anycurrently running py.test instance).
This also introduces the explicit "failed" state, which is not "not
passed" with py.test.