all Python 3unittestfunction
unittest.removeHandler()
Ctrl+C handling
Removes the Ctrl+C handler installed by installHandler() and restores the previous one; it also works as a decorator for a single test.
Syntax
unittest.removeHandler()
@unittest.removeHandler
def test_x(self): ...
Used as a decorator, @unittest.removeHandler removes the handler only for the duration of one test and then restores it. A test that checks its own reaction to KeyboardInterrupt needs this: under the unittest handler the first Ctrl+C never reaches the test code. Calling it with no handler installed does nothing.
Examples
import signal
import unittest
unittest.installHandler()
print(signal.getsignal(signal.SIGINT) is signal.default_int_handler) # → False
unittest.removeHandler()
print(signal.getsignal(signal.SIGINT) is signal.default_int_handler) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy