Skip to content

Commit

Permalink
do not catch SIGINT under pytest
Browse files Browse the repository at this point in the history
When running under pytest, we must not register a signal handler for
SIGINT (CTRL-C), as otherwise the pytest internal signal handling does
not work. This was also the root-cause, why we could not properly
terminate our tests by pressing CTRL-C.

Without that handler, the SIGINT raises a KeyboardInterrupt, which is
handeled by pytest and either stops the test execution or prints a
precise stacktrace of the current execution (which is valuable for
debugging hanging tests).

Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed Oct 23, 2024
1 parent 8b064af commit b847390
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kas/kas.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ def kas(argv):

loop = asyncio.get_event_loop()

for sig in (signal.SIGINT, signal.SIGTERM):
loop.add_signal_handler(sig, interruption)
loop.add_signal_handler(signal.SIGTERM, interruption)
# don't overwrite pytest's signal handler
if "PYTEST_CURRENT_TEST" not in os.environ:
loop.add_signal_handler(signal.SIGINT, interruption)
atexit.register(_atexit_handler)

try:
Expand Down

0 comments on commit b847390

Please sign in to comment.