psutil.tests

Test utilities.

Package Contents

TOX
PYPY
TRAVIS
APPVEYOR
PYPY
NO_RETRIES = 10
MEMORY_TOLERANCE
GLOBAL_TIMEOUT
VERBOSITY
TESTFILE_PREFIX = $testfn
TESTFILE_PREFIX = $psutil-test-
TESTFN
TESTFN
TESTFN_UNICODE
ROOT_DIR
SCRIPTS_DIR
HAS_CPU_AFFINITY
HAS_CPU_FREQ
HAS_ENVIRON
HAS_PROC_IO_COUNTERS
HAS_IONICE
HAS_MEMORY_FULL_INFO
HAS_MEMORY_MAPS
HAS_PROC_CPU_NUM
HAS_RLIMIT
HAS_SENSORS_BATTERY
HAS_BATTERY
HAS_SENSORS_FANS
HAS_SENSORS_TEMPERATURES
PYTHON_EXE
DEVNULL
VALID_PROC_STATUSES
get_test_subprocess(cmd=None, **kwds)

Creates a python subprocess which does nothing for 60 secs and return it as subprocess.Popen instance. If “cmd” is specified that is used instead of python. By default stdin and stdout are redirected to /dev/null. It also attemps to make sure the process is in a reasonably initialized state. The process is registered for cleanup on reap_children().

create_proc_children_pair()

Create a subprocess which creates another one as in: A (us) -> B (child) -> C (grandchild). Return a (child, grandchild) tuple. The 2 processes are fully initialized and will live for 60 secs and are registered for cleanup on reap_children().

create_zombie_proc()

Create a zombie process and return its PID.

pyrun(src, **kwds)

Run python ‘src’ code string in a separate interpreter. Returns a subprocess.Popen instance.

reap_children(recursive=False)

Terminate and wait() any subprocess started by this test suite and ensure that no zombies stick around to hog resources and create problems when looking for refleaks.

If resursive is True it also tries to terminate and wait() all grandchildren started by this process.

get_kernel_version()

Return a tuple such as (2, 6, 36).

get_winver()
wait_for_pid(pid)

Wait for pid to show up in the process list then return. Used in the test suite to give time the sub process to initialize.

wait_for_file(fname, delete=True, empty=False)

Wait for a file to be written on disk with some content.

call_until(fun, expr)

Keep calling function for timeout secs and exit if eval() expression is True.

safe_rmpath(path)

Convenience function for removing temporary test files or dirs

chdir(dirname)

Context manager which temporarily changes the current directory.

create_exe(outpath, c_code=None)

Creates an executable file in the given location.

unique_filename(prefix=TESTFILE_PREFIX, suffix='')
get_suite()
run_suite()
run_test_module_by_name(name)
retry_before_failing(retries=NO_RETRIES)

Decorator which runs a test function and retries N times before actually failing.

skip_on_access_denied(only_if=None)

Decorator to Ignore AccessDenied exceptions.

skip_on_not_implemented(only_if=None)

Decorator to Ignore NotImplementedError exceptions.

get_free_port(host='127.0.0.1')

Return an unused TCP port.

unix_socket_path(suffix='')

A context manager which returns a non-existent file name and tries to delete it on exit.

bind_socket(family=AF_INET, type=SOCK_STREAM, addr=None)

Binds a generic socket.

bind_unix_socket(name, type=socket.SOCK_STREAM)

Bind a UNIX socket.

tcp_socketpair(family, addr=('', 0))

Build a pair of TCP sockets connected to each other. Return a (server, client) tuple.

unix_socketpair(name)

Build a pair of UNIX sockets connected to each other through the same UNIX file name. Return a (server, client) tuple.

create_sockets()

Open as many socket families / types as possible.

check_net_address(addr, family)

Check a net address validity. Supported families are IPv4, IPv6 and MAC addresses.

check_connection_ntuple(conn)

Check validity of a connection namedtuple.

reload_module(module)

Backport of importlib.reload of Python 3.3+.

import_module_by_path(path)
warn(msg)

Raise a warning msg.

is_namedtuple(x)

Check if object is an instance of namedtuple.

copyload_shared_lib(dst_prefix=TESTFILE_PREFIX)

Ctx manager which picks up a random shared CO lib used by this process, copies it in another location and loads it in memory via ctypes. Return the new absolutized path.