Commit 4ed3bb7f authored by Ezio Melotti's avatar Ezio Melotti

#17249: convert a test in test_capi to use unittest and reap threads.

parent 7dddbb2b
...@@ -8,6 +8,7 @@ import random ...@@ -8,6 +8,7 @@ import random
import subprocess import subprocess
import sys import sys
import time import time
import _thread
import unittest import unittest
from test import support from test import support
try: try:
...@@ -222,21 +223,13 @@ class EmbeddingTest(unittest.TestCase): ...@@ -222,21 +223,13 @@ class EmbeddingTest(unittest.TestCase):
os.chdir(oldcwd) os.chdir(oldcwd)
def test_main(): @unittest.skipUnless(threading, 'Threading required for this test.')
support.run_unittest(CAPITest, TestPendingCalls, Test6012, EmbeddingTest) class TestThreadState(unittest.TestCase):
for name in dir(_testcapi):
if name.startswith('test_'):
test = getattr(_testcapi, name)
if support.verbose:
print("internal", name)
test()
@support.reap_threads
def test_thread_state(self):
# some extra thread-state tests driven via _testcapi # some extra thread-state tests driven via _testcapi
def TestThreadState(): def target():
if support.verbose:
print("auto-thread-state")
idents = [] idents = []
def callback(): def callback():
...@@ -246,18 +239,25 @@ def test_main(): ...@@ -246,18 +239,25 @@ def test_main():
a = b = callback a = b = callback
time.sleep(1) time.sleep(1)
# Check our main thread is in the list exactly 3 times. # Check our main thread is in the list exactly 3 times.
if idents.count(_thread.get_ident()) != 3: self.assertEqual(idents.count(_thread.get_ident()), 3,
raise support.TestFailed(
"Couldn't find main thread correctly in the list") "Couldn't find main thread correctly in the list")
if threading: target()
import _thread t = threading.Thread(target=target)
import time
TestThreadState()
t = threading.Thread(target=TestThreadState)
t.start() t.start()
t.join() t.join()
def test_main():
support.run_unittest(CAPITest, TestPendingCalls, Test6012,
EmbeddingTest, TestThreadState)
for name in dir(_testcapi):
if name.startswith('test_'):
test = getattr(_testcapi, name)
if support.verbose:
print("internal", name)
test()
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
...@@ -936,6 +936,8 @@ Extension Modules ...@@ -936,6 +936,8 @@ Extension Modules
Tests Tests
----- -----
- Issue #17249: convert a test in test_capi to use unittest and reap threads.
- Issue #17041: Fix testing when Python is configured with the - Issue #17041: Fix testing when Python is configured with the
--without-doc-strings. --without-doc-strings.
......
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