When using -x / --maxfail the Interrupted exception is thrown, and gets handled in the same place as KeyboardInterrupt (
|
except KeyboardInterrupt: |
|
excinfo = _pytest._code.ExceptionInfo() |
|
if initstate < 2 and isinstance( |
|
excinfo.value, pytest.exit.Exception): |
|
sys.stderr.write('{0}: {1}\n'.format( |
|
excinfo.typename, excinfo.value.msg)) |
|
config.hook.pytest_keyboard_interrupt(excinfo=excinfo) |
|
session.exitstatus = EXIT_INTERRUPTED |
), because it is a subclass.
Therefore I think the hook name is confusing / misleading.
If this behavior is intentional, it should get added to the documentation at least.
I have noticed this, because pytest-testmon uses this hook to not save its data: https://github.com/tarpas/pytest-testmon/blob/55c89bb3df65c94e226ead8dd465f3dd5bb8927b/testmon/pytest_testmon.py#L173-L174
Here a check using excinfo.typename could be added to handle 'Interrupted' different from 'KeyboardInterrupt'.
btw: is there a way to import the Interrupted class from pytest?
When using
-x/--maxfailthe Interrupted exception is thrown, and gets handled in the same place asKeyboardInterrupt(pytest/_pytest/main.py
Lines 99 to 106 in 86ec3f3
Therefore I think the hook name is confusing / misleading.
If this behavior is intentional, it should get added to the documentation at least.
I have noticed this, because pytest-testmon uses this hook to not save its data: https://github.com/tarpas/pytest-testmon/blob/55c89bb3df65c94e226ead8dd465f3dd5bb8927b/testmon/pytest_testmon.py#L173-L174
Here a check using
excinfo.typenamecould be added to handle 'Interrupted' different from 'KeyboardInterrupt'.btw: is there a way to import the
Interruptedclass from pytest?