Skip to content

Pytest Plugin Which Reports System Usage Statistics

License

Notifications You must be signed in to change notification settings

saltstack/pytest-system-statistics

Repository files navigation

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.

About

Pytest Plugin Which Reports System Usage Statistics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages