pytest-cleanuptotal


Namepytest-cleanuptotal JSON
Version 0.3.7 PyPI version JSON
download
home_pagehttps://github.com/tzurp/pytest_cleanuptotal
SummaryA cleanup plugin for pytest
upload_time2025-07-22 12:51:10
maintainerTzur Paldi
docs_urlNone
authorTzur Paldi
requires_pythonNone
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-cleanuptotal

This plugin for [pytest](https://github.com/pytest-dev/pytest) and for [playwright-pytest](https://github.com/microsoft/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](https://www.linkedin.com/pulse/test-automation-cleanup-advanced-plugin-playwright-tzur-paldi-phd/?trackingId=8R68dOtBSHKrCH0cNAviIA%3D%3D).

## 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:

```python
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:

```python
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](mailto:tzur.paldi@outlook.com?subjet=pytest-cleanuptotal%20Support)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tzurp/pytest_cleanuptotal",
    "name": "pytest-cleanuptotal",
    "maintainer": "Tzur Paldi",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "tzur.paldi@outlook.com",
    "keywords": null,
    "author": "Tzur Paldi",
    "author_email": "tzur.paldi@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/25/87/849738858b4930ca4103c299fa83e4aadba94d6f9ecf4adfa5d424e411be/pytest_cleanuptotal-0.3.7.tar.gz",
    "platform": null,
    "description": "# pytest-cleanuptotal\r\n\r\nThis plugin for [pytest](https://github.com/pytest-dev/pytest) and for [playwright-pytest](https://github.com/microsoft/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](https://www.linkedin.com/pulse/test-automation-cleanup-advanced-plugin-playwright-tzur-paldi-phd/?trackingId=8R68dOtBSHKrCH0cNAviIA%3D%3D).\r\n\r\n## Installation\r\n\r\n```\r\n$ pip install pytest-cleanuptotal\r\n```\r\n\r\n## Usage\r\n\r\nTo 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:\r\n\r\n```python\r\ndef test_should_keep_things_tidy(cleanuptotal):\r\n            # ...\r\n\r\n            account_id = create_account(\"John Blow\");\r\n            amount = 1000000\r\n            \r\n            # usage of cleanuptotal with lambda function:\r\n            cleanuptotal.add_cleanup(lambda: delete_account(account_id))\r\n\r\n            add_investment_plan(account_id, \"ModRisk\");\r\n\r\n            cleanuptotal.add_cleanup(lambda: remove_investment_plan(account_id))\r\n            \r\n            deposit(account_id, amount);\r\n\r\n            def remove_deposit():\r\n              url = f\"https://api.example.com/user/{accountId}/withdraw\"\r\n              data = {\"amount\": amount}\r\n              response = requests.post(url, json=data)\r\n            \r\n            # usage of cleanuptotal with regular function:\r\n            cleanuptotal.add_cleanup(remove_deposit)\r\n\r\n            # ...\r\n\r\n        # Please note that the actual execution of the cleanup code would take palce AFTER test completion.\r\n        # Execution order in cleanuptotal would be remove_deposit() -> remove_investment_plan(account_id) -> delete_account(account_id).\r\n```\r\n\r\nTo use type hints follow this example:\r\n\r\n```python\r\nfrom pytest_cleanuptotal.cleanup import Cleanup\r\n\r\ndef test_should_keep_things_tidy(cleanuptotal:Cleanup):\r\n            # ... your test code here\r\n```\r\n\r\n## Logging\r\n\r\nTo see all the *pytest-cleanuptotal* logging change the log level to 'DEBUG' (e.g., in your project's pytest.ini)\r\n\r\n## Support\r\n\r\nFor any questions or suggestions contact me at: [tzur.paldi@outlook.com](mailto:tzur.paldi@outlook.com?subjet=pytest-cleanuptotal%20Support)\r\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A cleanup plugin for pytest",
    "version": "0.3.7",
    "project_urls": {
        "Bug Tracker": "https://github.com/tzurp/pytest_cleanuptotal/issues",
        "Documentation": "https://github.com/tzurp/pytest_cleanuptotal#readme",
        "Homepage": "https://github.com/tzurp/pytest_cleanuptotal",
        "Source Code": "https://github.com/tzurp/pytest_cleanuptotal"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e8a9bd36a2cceef30b370fe0134a3d470608690fbbe36025a4c40b5e048f07b9",
                "md5": "30a4add2058710d8365d281ef36fb674",
                "sha256": "6ac82cfa2a187f942f74003e73d571fa8491be679f6a8531ca2b13ee43cc949e"
            },
            "downloads": -1,
            "filename": "pytest_cleanuptotal-0.3.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30a4add2058710d8365d281ef36fb674",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9461,
            "upload_time": "2025-07-22T12:51:09",
            "upload_time_iso_8601": "2025-07-22T12:51:09.080243Z",
            "url": "https://files.pythonhosted.org/packages/e8/a9/bd36a2cceef30b370fe0134a3d470608690fbbe36025a4c40b5e048f07b9/pytest_cleanuptotal-0.3.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2587849738858b4930ca4103c299fa83e4aadba94d6f9ecf4adfa5d424e411be",
                "md5": "d31eb99485ce3a9b8b562189e7974eff",
                "sha256": "453a16bed8b89b67d6bf2ba3cf287c76d1c5c0dfc327a8ff1a64522ffe78536f"
            },
            "downloads": -1,
            "filename": "pytest_cleanuptotal-0.3.7.tar.gz",
            "has_sig": false,
            "md5_digest": "d31eb99485ce3a9b8b562189e7974eff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8022,
            "upload_time": "2025-07-22T12:51:10",
            "upload_time_iso_8601": "2025-07-22T12:51:10.035570Z",
            "url": "https://files.pythonhosted.org/packages/25/87/849738858b4930ca4103c299fa83e4aadba94d6f9ecf4adfa5d424e411be/pytest_cleanuptotal-0.3.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-22 12:51:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tzurp",
    "github_project": "pytest_cleanuptotal",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pytest-cleanuptotal"
}
        
Elapsed time: 1.36790s