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

Exit pytest cleanly "mid" run #3574

Closed
BeyondEvil opened this issue Jun 12, 2018 · 7 comments
Closed

Exit pytest cleanly "mid" run #3574

BeyondEvil opened this issue Jun 12, 2018 · 7 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@BeyondEvil
Copy link

I'm looking for certain conditions in the pytest_sessionstart() hook and I want to be able to stop/exit/abort further execution in a clean way.

Any idea how I can accomplish this? Neither pytest.exit() or sys.exit()/exit() does it cleanly.

Thanks!

@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #1421 (Exit pytest if a collection error occours), #471 (pytest keeps running deleted tests), #3106 (Exit code 1 when pytest crashes on loading plugin), #3556 ([Question] Can I run pytest on a read-only filesystem?), and #3557 (Run pytest on read-only file systems).

@pytestbot pytestbot added type: enhancement new feature or API change, should be merged into features branch type: question general question, might be closed after 2 weeks of inactivity labels Jun 12, 2018
@nicoddemus
Copy link
Member

Hi @BeyondEvil, what do you mean by "cleanly" exactly?

Raising session.Interrupted might be a solution.

@nicoddemus nicoddemus removed the type: enhancement new feature or API change, should be merged into features branch label Jun 12, 2018
@BeyondEvil
Copy link
Author

@nicoddemus Sorry, I should've been clearer.

I basically want to exit with exitstatus 0 (zero) and no warnings/errors.

I'll try raising session.Interrupted, but from the sound of it that won't give me exitstatus 0...

@nicoddemus
Copy link
Member

I see, thanks for the clarification.

I don't think there's support for that out of the box currently.

I guess it could be implemented by adding a statuscode or returncode to pytest.exit().

@ofek
Copy link
Contributor

ofek commented Oct 9, 2018

@nicoddemus Hello there! Has there been any progress on adding the ability to control the exit code?

@nicoddemus
Copy link
Member

@ofek not AFAIK. Seems it should be simple to implement if someone wants to give this a try. 😁

@nicoddemus nicoddemus changed the title Help: Exit pytest cleanly "mid" run? Exit pytest cleanly "mid" run Oct 9, 2018
@nicoddemus
Copy link
Member

I'm closing this one in favor of #4098 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

4 participants