PyDocs

Development Tools

test.support

The test.support module provides support for Python’s regression test suite.
Symbols in test.support

a

adjust_int_max_str_digits
This function returns a context manager that will change the global sys.set_int_max_str_digits() setting for the duration of the context to allow execution of test code that needs a different limit o…
ALWAYS_EQ
Object that is equal to anything.
anticipate_failure
A decorator to conditionally mark tests with @unittest.expectedFailure.
args_from_interpreter_flags
Return a list of command line arguments reproducing the current settings in sys.flags and sys.warnoptions.

b

bigaddrspacetest
Decorator for tests that fill the address space.
bigmemtest
Decorator for bigmem tests.
busy_retry
Run the loop body until break stops the loop.

c

calcobjsize
Return the size of the PyObject whose structure members are defined by fmt.
calcvobjsize
Return the size of the PyVarObject whose structure members are defined by fmt.
captured_stderr
A context managers that temporarily replaces the named stream with io.StringIO object.
captured_stdin
A context managers that temporarily replaces the named stream with io.StringIO object.
captured_stdout
A context managers that temporarily replaces the named stream with io.StringIO object.
catch_unraisable_exception
Context manager catching unraisable exception using sys.unraisablehook().
check__all__
Assert that the __all__ variable of module contains all public names.
check_disallow_instantiation
Assert that type tp cannot be instantiated using args and kwds.
check_free_after_iterating
Assert instances of cls are deallocated after iterating.
check_impl_detail
Use this check to guard CPython’s implementation-specific tests or to run them only on the implementations guarded by the arguments.
check_syntax_error
Test for syntax errors in statement by attempting to compile statement.
checksizeof
For testcase test, assert that the sys.getsizeof for o plus the GC header size equals size.
cpython_only
Decorator for tests only applicable to CPython.

d

detect_api_mismatch
Returns the set of attributes, functions or methods of ref_api not found on other_api, except for a defined list of items to be ignored in this check specified in ignore.
disable_faulthandler
A context manager that temporary disables faulthandler.
disable_gc
A context manager that disables the garbage collector on entry.

f

findfile
Return the path to the file named filename.
flush_std_streams
Call the flush() method on sys.stdout and then on sys.stderr.

g

gc_collect
Force as many objects as possible to be collected.
get_attribute
Get an attribute, raising unittest.SkipTest if AttributeError is raised.
get_original_stdout
Return the original stdout set by record_original_stdout() or sys.stdout if it’s not set.
get_pagesize
Get size of a page in bytes.
get_resource_value
Return the value specified for resource (as -u resource=value).

h

HAVE_DOCSTRINGS
Set to True if function docstrings are available.

i

impl_detail
Decorator for invoking check_impl_detail() on guards.
INTERNET_TIMEOUT
Timeout in seconds for network requests going to the internet.
is_android
True if sys.platform is android.
is_apple
True if sys.platform is darwin or is_apple_mobile is True.
is_apple_mobile
True if sys.platform is ios, tvos, or watchos.
is_emscripten
True if sys.platform is emscripten.
is_jython
True if the running interpreter is Jython.
is_resource_enabled
Return True if resource is enabled and available.
is_wasi
True if sys.platform is wasi.
isolation.runInSubprocess
Decorator that runs the decorated test in a fresh interpreter subprocess, in isolation, so that it does not share global or interpreter state with the rest of the test run.
isolation.runningInSubprocess
True while the code runs in the isolated subprocess spawned by runInSubprocess(), and False otherwise (including in the parent process and in a normal, non-isolated test run).

l

LARGEST
Object that is greater than anything (except itself).
linked_to_musl
Return False if there is no evidence the interpreter was compiled with musl, otherwise return a version triple, either (0, 0, 0) if the version is unknown, or the actual version if it is known.
load_package_tests
Generic implementation of the unittest load_tests protocol for use in test packages.
LONG_TIMEOUT
Timeout in seconds to detect when a test hangs.
LOOPBACK_TIMEOUT
Timeout in seconds for tests using a network server listening on the network local loopback interface like 127.0.0.1.

m

max_memuse
Set by set_memlimit() as the memory limit for big memory tests.
MAX_Py_ssize_t
Set to sys.maxsize for big memory tests.
MISSING_C_DOCSTRINGS
Set to True if Python is built without docstrings (the WITH_DOC_STRINGS macro is not defined).
missing_compiler_executable
Check for the existence of the compiler executables whose names are listed in cmd_names or all the compiler executables when cmd_names is empty and return the first missing executable or None when no…

n

NEVER_EQ
Object that is not equal to anything (even to ALWAYS_EQ).
no_tracing
Decorator to temporarily turn off tracing for the duration of the test.

o

optim_args_from_interpreter_flags
Return a list of command line arguments reproducing the current optimization settings in sys.flags.

p

patch
Override object_to_patch.attr_name with new_value.
PGO
Set when tests can be skipped when they are not useful for PGO.
PIPE_MAX_SIZE
A constant that is likely larger than the underlying OS pipe buffer size, to make writes blocking.
print_warning
Print a warning into sys.__stderr__.
Py_DEBUG
True if Python was built with the Py_DEBUG macro defined, that is, if Python was built in debug mode.
python_is_optimized
Return True if Python was not built with -O0 or -Og.

r

real_max_memuse
Set by set_memlimit() as the memory limit for big memory tests.
reap_children
Call this from setUp(), tearDown(), or tearDownModule() in tests that start subprocesses.
record_original_stdout
Store the value from stdout.
refcount_test
Decorator for tests which involve reference counting.
requires
Raise ResourceDenied if resource is not available.
requires_bz2
Decorator for skipping tests if bz2 doesn’t exist.
requires_docstrings
Decorator for only running the test if HAVE_DOCSTRINGS.
requires_freebsd_version
Decorator for the minimum version when running test on FreeBSD.
requires_gil_enabled
Decorator for skipping tests on the free-threaded build.
requires_gzip
Decorator for skipping tests if gzip doesn’t exist.
requires_IEEE_754
Decorator for skipping tests on non-IEEE 754 platforms.
requires_limited_api
Decorator for only running the test if Limited C API is available.
requires_linux_version
Decorator for the minimum version when running test on Linux.
requires_lzma
Decorator for skipping tests if lzma doesn’t exist.
requires_mac_version
Decorator for the minimum version when running test on macOS.
requires_resource
Decorator for skipping tests if resource is not available.
requires_zlib
Decorator for skipping tests if zlib doesn’t exist.
ResourceDenied
Subclass of unittest.SkipTest.
run_in_subinterp
Run code in subinterpreter.
run_with_locale
A decorator for running a function in a different locale, correctly resetting it after it has finished.
run_with_tz
A decorator for running a function in a specific timezone, correctly resetting it after it has finished.

s

SaveSignals
Class to save and restore signal handlers registered by the Python signal handler.
set_memlimit
Set the values for max_memuse and real_max_memuse for big memory tests.
setswitchinterval
Set the sys.setswitchinterval() to the given interval.
SHORT_TIMEOUT
Timeout in seconds to mark a test as failed if the test takes “too long”.
skip_if_broken_multiprocessing_synchronize
Skip tests if the multiprocessing.synchronize module is missing, if there is no available semaphore implementation, or if creating a lock raises an OSError.
sleeping_retry
Wait strategy that applies exponential backoff.
SMALLEST
Object that is less than anything (except itself).
SOCK_MAX_SIZE
A constant that is likely larger than the underlying OS socket buffer size, to make writes blocking.
sortdict
Return a repr of dict with keys sorted.
SuppressCrashReport
A context manager used to try to prevent crash dialog popups on tests that are expected to crash a subprocess.
swap_attr
Context manager to swap out an attribute with a new object.
swap_item
Context manager to swap out an item with a new object.
system_must_validate_cert
A decorator that skips the decorated test on TLS certification validation failures.

t

TEST_DATA_DIR
Set to the data directory within the test package.
TEST_HOME_DIR
Set to the top level directory for the test package.
TEST_HTTP_URL
Define the URL of a dedicated HTTP server for the network tests.
TEST_SUPPORT_DIR
Set to the top level directory that contains test.support.
TestFailed
Exception to be raised when a test fails.
thread_unsafe
Decorator for marking tests as thread-unsafe.

u

unix_shell
Path for shell if not on Windows; otherwise None.

v

verbose
True when verbose output is enabled.

w

wait_process
Wait until process pid completes and check that the process exit code is exitcode.
with_pymalloc
Return True if Python was built with pymalloc enabled and is not a free-threaded build.