MCPcopy Index your code
hub / github.com/python/cpython / testHandlerReplacedButCalled

Method testHandlerReplacedButCalled

Lib/test/test_unittest/test_break.py:149–172  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

147
148
149 def testHandlerReplacedButCalled(self):
150 # Can't use skipIf decorator because the signal handler may have
151 # been changed after defining this method.
152 if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
153 self.skipTest("test requires SIGINT to not be ignored")
154
155 def test_function():
156 # If our handler has been replaced (is no longer installed) but is
157 # called by the *new* handler, then it isn't safe to delay the
158 # SIGINT and we should immediately delegate to the default handler
159 unittest.installHandler()
160
161 handler = signal.getsignal(signal.SIGINT)
162 def new_handler(frame, signum):
163 handler(frame, signum)
164 signal.signal(signal.SIGINT, new_handler)
165
166 try:
167 os.kill(os.getpid(), signal.SIGINT)
168 except KeyboardInterrupt:
169 pass
170 else:
171 self.fail("replaced but delegated handler doesn't raise interrupt")
172 self.withRepeats(test_function)
173
174 def testRunner(self):
175 # Creating a TextTestRunner with the appropriate argument should

Callers

nothing calls this directly

Calls 2

withRepeatsMethod · 0.95
skipTestMethod · 0.80

Tested by

no test coverage detected