test — Regression tests package for Python — Python 3.14.7 documentation

docs.python.org

Tin mới

unittest.mock — getting started

Debugging and Profiling

Python Module Index

3.14.7 Documentation

The Python Standard Library

unittest: Unit testing framework for Python.

The test package is meant for internal use by Python only. It is documented for the benefit of the core developers of Python. Any use of this package outside of Python’s standard library is discouraged as code mentioned

doctest: Test pieces of code within docstrings.

The test package is meant for internal use by Python only. It is documented for the benefit of the core developers of Python. Any use of this package outside of Python’s standard library is discouraged as code mentioned

Running tests using the command-line interface¶

Some other ways to execute the regression tests depend on what platform the tests are being executed on. On Unix, you can run make test at the top-level directory where Python was built. On Windows, executing rt.bat from

socket.socket.connect

Timeout in seconds for tests using a network server listening on the network local loopback interface like 127.0.0.1.

built in debug mode

True if Python was built with the Py_DEBUG macro defined, that is, if Python was built in debug mode.

sys.setswitchinterval()

Set the sys.setswitchinterval() to the given interval. Defines a minimum interval for Android systems to prevent the system from hanging.

faulthandler: Dump the Python traceback.

A context manager that temporary disables faulthandler.

zlib: Low-level interface to compression and decompression routines compatible with gzip.

Decorator for skipping tests if zlib doesn’t exist.

gzip: Interfaces for gzip compression and decompression using file objects.

Decorator for skipping tests if gzip doesn’t exist.

bz2: Interfaces for bzip2 compression and decompression.

Decorator for skipping tests if bz2 doesn’t exist.

lzma: A Python wrapper for the liblzma compression library.

Decorator for skipping tests if lzma doesn’t exist.

tracemalloc: Trace memory allocations.

Run code in subinterpreter. Raise unittest.SkipTest if tracemalloc is enabled.

definition.__module__

Assert that the __all__ variable of module contains all public names.

resource.setrlimit()

A context manager used to try to prevent crash dialog popups on tests that are expected to crash a subprocess.

subprocess.Popen()

kw is extra keyword args to pass to subprocess.Popen(). Returns a subprocess.Popen object.

threading.Event.set()

Context manager to start threads, which is a sequence of threads. unlock is a function called after the threads are started, even if an exception was raised; an example would be threading.Event.set(). start_threads will

os.PathLike.__fspath__

Simple path-like object. It implements the __fspath__() method which just returns the path argument. If path is an exception, it will be raised in __fspath__().

tempfile.mkdtemp()

A context manager that temporarily creates a new directory and changes the current working directory (CWD).

DeprecationWarning

A context manager to force import to return a new module reference. This is useful for testing module-level behaviors, such as the emission of a DeprecationWarning on import. Example usage:

warnings.catch_warnings()

Suppress warnings that are instances of category, which must be Warning or a subclass. Roughly equivalent to warnings.catch_warnings() with warnings.simplefilter('ignore', category=category). For example: