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

--pdb treats KeyboardInterrupt as exception #3436

Conversation

brianmaissy
Copy link
Contributor

Fixes #3299

@coveralls
Copy link

coveralls commented Apr 30, 2018

Coverage Status

Coverage increased (+0.05%) to 92.779% when pulling 1a880be on brianmaissy:feature/enter_pdb_on_keyboard_interrupt into 5ba0663 on pytest-dev:features.



class CallInfo(object):
""" Result/Exception info a function invocation. """
#: None or ExceptionInfo object.
excinfo = None

def __init__(self, func, when):
def __init__(self, func, when, usepdb=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about passing in the whole item?
Would make it more flexible for future changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind changing it.

I figured it was cleaner to pass the minimum information I need to accomplish the task, passing more seemed like premature optimization.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to pass just what you need as well. I would name the parameter differently as well, because it is more about treating KeyboardInterrupt as a special case... how about stop_on_keyboard_interrupt=True?

Copy link
Contributor Author

@brianmaissy brianmaissy May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, but in either case we are going to stop on keyboard interrupt. Either we capture the exception or we re-raise it. How about calling it treat_keyboard_interrupt_as_exception?



class CallInfo(object):
""" Result/Exception info a function invocation. """
#: None or ExceptionInfo object.
excinfo = None

def __init__(self, func, when):
def __init__(self, func, when, usepdb=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to pass just what you need as well. I would name the parameter differently as well, because it is more about treating KeyboardInterrupt as a special case... how about stop_on_keyboard_interrupt=True?

@@ -382,7 +385,8 @@ def __init__(self, longrepr, **extra):
def pytest_make_collect_report(collector):
call = CallInfo(
lambda: list(collector.collect()),
'collect')
'collect',
None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should treat this option as a bool, so this should be False; but I think we also want to stop on the debugger during collection, so we should pass the parameter here based on config.getvalue("usepdb").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is someone going to do with a debugger in the middle of runner.py?
I guess they could check the sys.path or something like that, but I'm worried about throwing them into a debugger in the middle of the pytest internals

@@ -0,0 +1 @@
The ``--pdb`` option now causes KeyboardInterrupt to enter the debugger, instead of stopping the test session.
Copy link
Member

@nicoddemus nicoddemus May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure: hitting CTRL+C again after landing on the debugger causes the debugger to exit right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'll try to add a test that verifies that. Should I mention it in the changelog or docs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just mentioning it in the changelog is sufficient, something like:

... instead of stopping the test session. Hitting CTRL+C again exits the debugger.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the test failed... not sure if it is easy to fix it; if not I'm OK with dropping the test, I think it is enough to ensure that we enter pdb when we get a KeyboardInterrupt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also expected the test to fail because of pexpect's kill method not being cross-platform or something like that, but actually the test failed because pdb indeed behaves differently in python 3.6, and the KeyboardInterrupt does not cause it to exit. Are we ok with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it was an intentional change: https://bugs.python.org/issue7245.
Haha now I understand the discussion on the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nosigint parameter to the Pdb constructor is supposed to disable that functionality, according to the docs (https://docs.python.org/3/library/pdb.html#pdb.Pdb). For some reason it doesn't seem to be working for me, but I can continue looking into it if we care about it.

On the other hand, probably better to let the pdb act like it usually acts for each version of python.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, probably better to let the pdb act like it usually acts for each version of python.

Definitely, I agree! Thanks for researching this. 👍

@brianmaissy brianmaissy force-pushed the feature/enter_pdb_on_keyboard_interrupt branch from d950dde to c258fe1 Compare May 1, 2018 21:58
@nicoddemus
Copy link
Member

Awesome work @brianmaissy, thanks a lot!

@nicoddemus
Copy link
Member

The py27-xdist failure on AppVeyor is unrelated so I think this is ready for merging.

@RonnyPfannschmidt would you like to review this as well?

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current iteration is quite nice - in particular the chatty name is important for me and the logic is nice and simple now

thanks for bringing it to this point

@nicoddemus nicoddemus merged commit b03b387 into pytest-dev:features May 3, 2018
@brianmaissy brianmaissy deleted the feature/enter_pdb_on_keyboard_interrupt branch May 4, 2018 09:24
@nicoddemus nicoddemus mentioned this pull request Jul 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants