Skip to main content

Detects thread leaks

Project description

Status of Github Actions python tests workflow

Detects tests leaking threads

Installation

You can install “pytest-threadleak” via pip from PyPI:

$ pip install pytest-threadleak

Usage

The threadleak pytest plugin will fail leaking threads. This can be an issue in the test, or in the tested code.

Here is an example leaking test:

$ cat leak_test.py
import threading
import time

def test_leak():
    threading.Thread(target=time.sleep, args=(1,)).start()

Here is an example run with thread leak plugin enabled:

$ pytest --threadleak leak_test.py
...
leak_test.py::test_leak FAILED
...
>   ???
E   Failed: Test leaked [<Thread(Thread-1, started 139762716391168)>]

If you want to enable thread leak by default, you can enable it in your pytest.ini or tox.ini:

[pytest]
threadleak = True

If you want to enable thread leak on a per test/module basis, you can use the threadleak pytest marker:

To enable it for a single test:

@pytest.mark.threadleak
def test_leak():
   ...

To disable it for a single test:

@pytest.mark.threadleak(enabled=False)
def test_leak():
   ...

For an entire test module:

import pytest

pytestmark = pytest.mark.threadleak(enabled=False)

Contributing

Running the tests:

$ tox

License

Distributed under the terms of the MIT license, “pytest-threadleak” is free and open source software

Credits

This Pytest plugin was generated with Cookiecutter along with @hackebrot’s Cookiecutter-pytest-plugin template.

Download files

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

Source Distribution

pytest-threadleak-0.4.0.tar.gz (4.0 kB view hashes)

Uploaded source

Built Distribution

pytest_threadleak-0.4.0-py3-none-any.whl (3.5 kB view hashes)

Uploaded py3

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