Skip to main content

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

            accountId = createAccount("John Blow");
            amount = 1000000
            
            # usage of cleanuptotal with lambda function:
            cleanuptotal.addCleanup(lambda: deleteAccount(accountId))

            addInvestmentPlan(accountId, "ModRisk");

            cleanuptotal.addCleanup(lambda: removeInvestmentPlan(accountId))
            
            deposit(accountId, amount);

            def removeDeposit():
              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.addCleanup(removeDeposit)

            # ...

        # Please note that the actual execution of the cleanup code would take palce AFTER test completion.
        # Execution order in cleanuptotal would be removeDeposit() -> removeInvestmentPlan(accountId) -> deleteAccount(accountId).

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

pytest-cleanuptotal-0.2.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

pytest_cleanuptotal-0.2.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest-cleanuptotal-0.2.1.tar.gz.

File metadata

  • Download URL: pytest-cleanuptotal-0.2.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pytest-cleanuptotal-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0dfde4bb551aed2492af5bf6756117da85028574a739e988b45dc44c932a02c9
MD5 93c99bc1a3ec44765443dd13c030a0ec
BLAKE2b-256 c15dc388174b754f56a025b545d407a3f5649473eaa99495636041e1e6ae605e

See more details on using hashes here.

File details

Details for the file pytest_cleanuptotal-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_cleanuptotal-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 82d7e6fe22803d48eda8113c3dc6fbb6a973903998b01f4fe4f077a1ffd8f2ba
MD5 87ffde42596385d654b3f66d10504cbf
BLAKE2b-256 5e83b98f54bc19f78ce585c45f6d6a7e9b01410b6d4b24fd0d8a32963fd89ce4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page