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

configuration option disabling sucicide on pytest subprocess #1791

Closed
hernot opened this issue Jan 10, 2021 · 4 comments
Closed

configuration option disabling sucicide on pytest subprocess #1791

hernot opened this issue Jan 10, 2021 · 4 comments
Labels
feature:new something does not exist yet, but should help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted.

Comments

@hernot
Copy link

hernot commented Jan 10, 2021

Describe what improvement you want and how would this be used. Thanks!
I sometimes need to run pytest under a newer python version eg py38 while my system is running python 3.6 or 3.7 in trace mode

pytest --trace <sometest>::<test_function>

to achieve this i prefer to call it through tox

tox -- --trace <sometest>::<test_function>

In tox.ini i have

[testenv]
comands =
  pytest {posargs}

This basically works as expected but some times the library runs into a endless loop or i want to check if some code executed between two breakpoints is working as expected. This when running pytest directly is achieved by pressing to bail out into pdb debugger. Under tox pytest will be killed after interrupt_timeout is elapsed which is annoying in this case. Therefore i would apriciate if there would be a tox no_suicide or dont_kill or alike option to tell tox to refrain from sending term signal to its subprocesses or at least pytest if specified as parameter for that option and just pass on SIGINT as SIGINT without killing itself..

@hernot hernot added the feature:new something does not exist yet, but should label Jan 10, 2021
@gaborbernat
Copy link
Member

I have never used the trace flag of pytest, so you'd need to tell more about it. Also what suicide are we talking here about, tox vs pytest?

@hernot
Copy link
Author

hernot commented Jan 13, 2021

On Mon, 2021-01-11 at 06:58 +0000, Bernát Gábor wrote:

I have never used the trace flag of pytest, so you'd need to tell
more about it. Also what suicide are we talking here about, tox vs
pytest?

Tox sends after suicide_timeout the sigint signal to all of its
subprocesses. If they do not react to it or do not terminate after
termination_timeout it sends according to documentation sig_term to
tell the subprocess like pytest to terminate and if it still does not
react tox sends finally the sig_kill before terminating it self after
all its subprocesses. Which is reasonable in most circumstances.

When you call pytest with --pdb parameter it will start post mortem
debugger in case an unhandled exception is thrown while executing a
test function and trerminate after. That is a first step to figure
which test fails wehere.

When you for in detail investigation call pytest with --trace
parameter it will run each test under the regime of python pdb debugger
as if one had inserted pdb.set_trace() at the beginning of each test
function or called python with -m pdb option activated to run the
testcode under the debugger directly. In pytest --trace mode one can
set breakpoints, walk up and down the stack and inspect variables
visible from within each stack frame as would be possible when running
the code directly with python -mpdb testmodule.py Just with the
difference that pytest allows to select which test function to put
under inspection through the debugger (pdb) in interactive mode. And in
this mode pdb will halt the execution of the program/test function at
each breakpoint and at what ever point along the execution stack it has
received the sigint signal and enters interactive mode allowing user to
inspect status of program, variables etc and figure why there is eg. an
endless loop etc. Quite helpful to track errors which seem (*) to occur
only for newer pyton versions.
Under the regime of tox the debugger still switches into interactive
mode when receiving sigint but as for tox it looks like as if it did
either ignore sigint or hang during termination request and kills it by
sigterm and if necessary sigkill, which is not the desired result in
this case.

(*) in most cases they just stay unnoticed in the version used to
develop the code

@gaborbernat gaborbernat added this to the 4.2 milestone Jan 13, 2022
@gaborbernat gaborbernat added the help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted. label Jun 16, 2023
@gaborbernat gaborbernat removed this from the P-2 milestone Jun 17, 2023
@gaborbernat
Copy link
Member

This issue was created for 3.x, which is no longer supported, please try with 4.0.

@hernot
Copy link
Author

hernot commented Jun 21, 2023

Thanks I'll do and report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:new something does not exist yet, but should help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted.
Projects
None yet
Development

No branches or pull requests

2 participants