Skip to main content

Pytest plugin to track and report system usage statistics

Project description

CI Docs Codecov Python Versions Python Wheel Code Style: black PyPI - License

What is Pytest System Statistics

It’s a pytest plugin, extracted from pytest-salt-factories, which tracks the test suite CPU and memory usage and, optionally, includes a report section including that data, for example:

test_proc_sys_stats.py::test_one PASSED                                                [100%]
----------------------------------- Processes Statistics ------------------------------------
  .......... System - CPU: 17.80 %  MEM: 29.70 % (Virtual Memory)  SWAP:  12.80 %
  .. Test Suite Run - CPU:  0.00 %  MEM:  0.05 % (RSS)  MEM SUM: 0.09 % (RSS)  CHILD PROCS: 2
  ...... FooProcess - CPU:  0.00 %  MEM:  0.02 % (RSS)  MEM SUM: 0.03 % (RSS)  CHILD PROCS: 1

==================================== 1 passed in 0.34s ======================================

Install

Installing Pytest System Statistics is as simple as:

python -m pip install pytest-system-statistics

Usage

Controlling the behaviour of the plugin is made through flags which are passed to pytest.

--sys-stats             Print System CPU and MEM statistics after each test execution.
--no-sys-stats          Do not print System CPU and MEM statistics after each test execution.
--sys-stats-no-children Don't include child processes memory statistics.
--sys-stats-uss-mem     Use the USS("Unique Set Size", memory unique to a process which
                        would be freed if the process was terminated) memory instead which
                        is more expensive to calculate.

Tracking Additional Processes

To include additional processes to track and report statistics against, simply add it to the session scoped stats_processes fixture, for example:

@pytest.fixture
def my_server_process(stats_processes):
    proc = subprocess.Popen(...)
    stats_processes.add("MyServerProcess", proc.pid)
    try:
        yield proc
    finally:
        stats_processes.remove("MyServerProcess")

Contributing

The pytest-system-statistics project team welcomes contributions from the community. For more detailed information, refer to CONTRIBUTING.

Documentation

The full documentation can be seen here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-system-statistics-1.0.2.tar.gz (56.9 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page