mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #7449, part 1: fix test_support.py for Python compiled without thread
This commit is contained in:
parent
ae9f8bd2f9
commit
d9d147b806
2 changed files with 20 additions and 4 deletions
|
@ -18,6 +18,10 @@ import importlib
|
||||||
import UserDict
|
import UserDict
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
try:
|
||||||
|
import thread
|
||||||
|
except ImportError:
|
||||||
|
thread = None
|
||||||
|
|
||||||
__all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
|
__all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
|
||||||
"verbose", "use_resources", "max_memuse", "record_original_stdout",
|
"verbose", "use_resources", "max_memuse", "record_original_stdout",
|
||||||
|
@ -44,7 +48,7 @@ class ResourceDenied(unittest.SkipTest):
|
||||||
"""Test skipped because it requested a disallowed resource.
|
"""Test skipped because it requested a disallowed resource.
|
||||||
|
|
||||||
This is raised when a test calls requires() for a resource that
|
This is raised when a test calls requires() for a resource that
|
||||||
has not be enabled. It is used to distinguish between expected
|
has not been enabled. It is used to distinguish between expected
|
||||||
and unexpected skips.
|
and unexpected skips.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -1078,11 +1082,14 @@ def run_doctest(module, verbosity=None):
|
||||||
# at the end of a test run.
|
# at the end of a test run.
|
||||||
|
|
||||||
def threading_setup():
|
def threading_setup():
|
||||||
import thread
|
if thread:
|
||||||
return thread._count(),
|
return thread._count(),
|
||||||
|
else:
|
||||||
|
return 1,
|
||||||
|
|
||||||
def threading_cleanup(nb_threads):
|
def threading_cleanup(nb_threads):
|
||||||
import thread
|
if not thread:
|
||||||
|
return
|
||||||
|
|
||||||
_MAX_COUNT = 10
|
_MAX_COUNT = 10
|
||||||
for count in range(_MAX_COUNT):
|
for count in range(_MAX_COUNT):
|
||||||
|
@ -1093,6 +1100,13 @@ def threading_cleanup(nb_threads):
|
||||||
# XXX print a warning in case of failure?
|
# XXX print a warning in case of failure?
|
||||||
|
|
||||||
def reap_threads(func):
|
def reap_threads(func):
|
||||||
|
"""Use this function when threads are being used. This will
|
||||||
|
ensure that the threads are cleaned up even when the test fails.
|
||||||
|
If threading is unavailable this function does nothing.
|
||||||
|
"""
|
||||||
|
if not thread:
|
||||||
|
return func
|
||||||
|
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def decorator(*args):
|
def decorator(*args):
|
||||||
key = threading_setup()
|
key = threading_setup()
|
||||||
|
|
|
@ -109,6 +109,8 @@ Extension Modules
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
- Issue #7449: Fix many tests to support Python compiled without thread support
|
||||||
|
|
||||||
- Issue #8108: test_ftplib's non-blocking SSL server now has proper handling
|
- Issue #8108: test_ftplib's non-blocking SSL server now has proper handling
|
||||||
of SSL shutdowns.
|
of SSL shutdowns.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue