Ensure a test produces no garbage
Project description
The purpose of this plugin is ensuring that portions of your Python code do not produce garbage or manually invoke garbage collection.
When the nogarbage pytest fixture is added to a test, it will cause an error under the following conditions:
Garbage was collected after the test was run (circular references were remaining after the test was broken down).
Garbage was explicitly collected (gc.collect()) during the test. Automatic garbage collection sweeps are disabled during the test.
You should use this plugin when:
You intend to run a program with garbage collection disabled in production.
You wish to verify elimination of garbage collection overhead produced by frequently called functions.
Requirements
Python 3.7+
This plugin is only tested against CPython.
Installation
You can install “pytest-nogarbage” via pip from PyPI:
$ pip install pytest-nogarbage
Usage
Add the nogarbage fixture to your test to ensure it does not produce garbage:
def test_circular(nogarbage): l1 = [] l2 = [l1] l2.append(l1) # ERROR: Garbage collected after test. def test_collect(nogarbage): import gc gc.collect() # ERROR: Garbage collected during test.
Recommended Reading
If you are interested in optimizing CPython garbage collection, the gc docs and CPython Garbage Collection devguide are excellent resources.
License
Distributed under the terms of the MIT license, “pytest-nogarbage” is free and open source software.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-nogarbage-1.0.0.tar.gz
.
File metadata
- Download URL: pytest-nogarbage-1.0.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5371bb19f0833422ba426ceef142e403d977963ea9d739faebd347bf9cbb3633 |
|
MD5 | ea02e6bd8caace11410761c5b7717591 |
|
BLAKE2b-256 | 5b5e4b03b4c94bbd37a202c6f0fdb9cadc468481565ef49e0de07be4bf28168d |
File details
Details for the file pytest_nogarbage-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_nogarbage-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fd77b6bc71705a6d396ccfe06f1a34cbfbb5f452a4dd15017d054a4195ef52d |
|
MD5 | ba3d942f81a3513d919f7c0adc6a19a7 |
|
BLAKE2b-256 | c934e5ad9f63449548332135546061ba72da66d4e7d85bab6a7aa32ca22da300 |