Kaydet (Commit) be595d33 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #7449, part 7: simplify threading detection in test_capi

 * Skip TestPendingCalls if threading module is missing
 * Test if threading module is present or not, instead of test the presence of
   _testcapi._test_thread_state
üst fd8ea992
...@@ -6,10 +6,14 @@ import sys ...@@ -6,10 +6,14 @@ import sys
import time import time
import random import random
import unittest import unittest
import threading
from test import test_support from test import test_support
try:
import threading
except ImportError:
threading = None
import _testcapi import _testcapi
@unittest.skipUnless(threading, 'Threading required for this test.')
class TestPendingCalls(unittest.TestCase): class TestPendingCalls(unittest.TestCase):
def pendingcalls_submit(self, l, n): def pendingcalls_submit(self, l, n):
...@@ -47,7 +51,6 @@ class TestPendingCalls(unittest.TestCase): ...@@ -47,7 +51,6 @@ class TestPendingCalls(unittest.TestCase):
print "(%i)"%(len(l),) print "(%i)"%(len(l),)
def test_pendingcalls_threaded(self): def test_pendingcalls_threaded(self):
#do every callback on a separate thread #do every callback on a separate thread
n = 32 #total callbacks n = 32 #total callbacks
threads = [] threads = []
...@@ -123,17 +126,10 @@ def test_main(): ...@@ -123,17 +126,10 @@ def test_main():
raise test_support.TestFailed, \ raise test_support.TestFailed, \
"Couldn't find main thread correctly in the list" "Couldn't find main thread correctly in the list"
try: if threading:
_testcapi._test_thread_state
have_thread_state = True
except AttributeError:
have_thread_state = False
if have_thread_state:
import thread import thread
import time import time
TestThreadState() TestThreadState()
import threading
t=threading.Thread(target=TestThreadState) t=threading.Thread(target=TestThreadState)
t.start() t.start()
t.join() t.join()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment