pytest-cleanuptotal
This plugin for pytest and for playwright-pytest helps simplify test cleanup. It does so by providing a systematic way to mark entities for deletion immediately after creation. This is particularly useful when tests involve creating complex structures, such as a bank account with an investment plan and a deposit. Without proper cleanup, attempting to delete the account may result in errors, such as a refusal due to the account not being empty. However, with pytest-cleanuptotal, entities are deleted in the correct order, ensuring that tests clean up after themselves and do not interfere with each other. Read more here.
Installation
$ pip install pytest-cleanuptotal
Usage
To use pytest-cleanuptotal, simply add the cleanuptotal fixture to the test method. This will include the cleanup functionality in your test. No further setup is required. Here's an example:
def test_should_keep_things_tidy(cleanuptotal):
# ...
account_id = create_account("John Blow");
amount = 1000000
# usage of cleanuptotal with lambda function:
cleanuptotal.add_cleanup(lambda: delete_account(account_id))
add_investment_plan(account_id, "ModRisk");
cleanuptotal.add_cleanup(lambda: remove_investment_plan(account_id))
deposit(account_id, amount);
def remove_deposit():
url = f"https://api.example.com/user/{accountId}/withdraw"
data = {"amount": amount}
response = requests.post(url, json=data)
# usage of cleanuptotal with regular function:
cleanuptotal.add_cleanup(remove_deposit)
# ...
# Please note that the actual execution of the cleanup code would take palce AFTER test completion.
# Execution order in cleanuptotal would be remove_deposit() -> remove_investment_plan(account_id) -> delete_account(account_id).
To use type hints follow this example:
from pytest_cleanuptotal.cleanup import Cleanup
def test_should_keep_things_tidy(cleanuptotal:Cleanup):
# ... your test code here
Logging
To see all the pytest-cleanuptotal logging change the log level to 'DEBUG' (e.g., in your project's pytest.ini)
Support
For any questions or suggestions contact me at: tzur.paldi@outlook.com
Metadata
Release files for pytest-cleanuptotal 0.3.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_cleanuptotal-0.3.7.tar.gz | 8.0 kB | Without provenance | Details for pytest_cleanuptotal-0.3.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_cleanuptotal-0.3.7-py3-none-any.whl | Python 3 | none | any | Details for pytest_cleanuptotal-0.3.7-py3-none-any.whl |
Total release size: 17.5 kB
Release files / pytest_cleanuptotal-0.3.7.tar.gz
| Download URL | pytest_cleanuptotal-0.3.7.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
453a16bed8b89b67d6bf2ba3cf287c76d1c5c0dfc327a8ff1a64522ffe78536f
|
|
BLAKE2b-256 checksum How to use checksums |
2587849738858b4930ca4103c299fa83e4aadba94d6f9ecf4adfa5d424e411be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / pytest_cleanuptotal-0.3.7-py3-none-any.whl
| Download URL | pytest_cleanuptotal-0.3.7-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ac82cfa2a187f942f74003e73d571fa8491be679f6a8531ca2b13ee43cc949e
|
|
BLAKE2b-256 checksum How to use checksums |
e8a9bd36a2cceef30b370fe0134a3d470608690fbbe36025a4c40b5e048f07b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for pytest-cleanuptotal 0.3.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.