Skip to content

pytest_keyboard_interrupt called on collection error #11200

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

Open
The-Compiler opened this issue Jul 11, 2023 Discussed in #11199 · 4 comments
Open

pytest_keyboard_interrupt called on collection error #11200

The-Compiler opened this issue Jul 11, 2023 Discussed in #11199 · 4 comments
Labels
topic: collection related to the collection phase

Comments

@The-Compiler
Copy link
Member

Discussed in #11199

Originally posted by eleanorjboyd July 11, 2023
Quick question on pytest_keyboard_interrupt. When I use a pytest plugin and the tests I am running my plugin on have a ModuleNotFoundError my plugin calls both the pytest_exception_interact hook and then the pytest_keyboard_interrupt hook. Why is pytest_keyboard_interrupt called for a ModuleNotFoundError? Is there any way to make it so it hits only one of the exception hooks? I am trying to keep track of the number of errors hit during discovery and a single error triggering two error hooks is making that more complicated. Also open to suggestions regarding another work-around. Thanks!

@The-Compiler The-Compiler added the topic: collection related to the collection phase label Jul 11, 2023
@The-Compiler
Copy link
Member Author

Also see #1865 which was a similar issue we fixed with --maxfail.

Reproducer conftest.py:

def pytest_keyboard_interrupt():
    print("keyboard interrupt")

def pytest_exception_interact():
    print("exception interact")

and test_x.py:

import doesnotexist

@symonk
Copy link
Member

symonk commented Jul 23, 2023

Hi @The-Compiler had quick look and yeah it looks like Session.Interrupted still remains a subclass of KeyboardInterrupt sadly, changing that looks sizable - is it sufficient do you think to add some specifics to wrap_session to only invoke the keyboard_interrupt hook if typename/type matches KeyboardInterrupt exception explicitly?

Thanks

@The-Compiler
Copy link
Member Author

Personally I'd rather have a proper fix rather than adding hacks on top of something that's already rather questionable...

@symonk
Copy link
Member

symonk commented Jul 23, 2023

sounds good, it does seem odd the class hierarchy there, possibly worth a wider discussion, some good points in the initial #1865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase
Projects
None yet
Development

No branches or pull requests

2 participants