Skip to content

--pdb treats KeyboardInterrupt as exception - #3436

Merged
nicoddemus merged 2 commits into
pytest-dev:featuresfrom
brianmaissy:feature/enter_pdb_on_keyboard_interrupt
May 3, 2018
Merged

--pdb treats KeyboardInterrupt as exception#3436
nicoddemus merged 2 commits into
pytest-dev:featuresfrom
brianmaissy:feature/enter_pdb_on_keyboard_interrupt

Conversation

@brianmaissy

Copy link
Copy Markdown
Contributor

Fixes #3299

@coveralls

coveralls commented Apr 30, 2018

Copy link
Copy Markdown

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.

Comment thread _pytest/runner.py Outdated
excinfo = None

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@brianmaissy brianmaissy May 1, 2018

Copy link
Copy Markdown
Contributor Author

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?

Comment thread _pytest/runner.py Outdated
excinfo = None

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

Copy link
Copy Markdown
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?

Comment thread _pytest/runner.py Outdated
lambda: list(collector.collect()),
'collect')
'collect',
None)

Copy link
Copy Markdown
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
Copy Markdown
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.

@nicoddemus nicoddemus May 1, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Awesome work @brianmaissy, thanks a lot!

@nicoddemus

Copy link
Copy Markdown
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?

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Copy link
Copy Markdown
Member

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