A cleanup plugin for pytest
Project description
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
Support
For any questions or suggestions contact me at: tzur.paldi@outlook.com
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
Built Distribution
File details
Details for the file pytest_cleanuptotal-0.2.2.tar.gz
.
File metadata
- Download URL: pytest_cleanuptotal-0.2.2.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff492f9a0c117aba4cbe7d2346d4d22db61f04c98e42132ab47bf2335be9e6b3 |
|
MD5 | dae0ae1f536b20a0c9ad883e27008a9a |
|
BLAKE2b-256 | c418cbd0fa31f4a48179b8420712c111b59e78357270df0a55e57faa97b8d3be |
File details
Details for the file pytest_cleanuptotal-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: pytest_cleanuptotal-0.2.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81394872e6b471dd90eba2f84fe2d9db21c240261d5f3701f3aad6cf61b8c91f |
|
MD5 | bf6739ea718141974dd05abc53eb1115 |
|
BLAKE2b-256 | 04d0ddb162c4b9069436dfb8f6da5ebea1d7532d028ad5683264c2fbf36ebec1 |