A setup/teardown context manager decorator for unit tests
Project description
Setup Teardown Content Decorator
This is a simple package that aims to make adding setup and teardown to pytest flavored tests quick and painless.
Installation
python3 -m pip install setup-teardown
Provided Postgres Database Class Decorator Usage
Extend and implement the session.
class TableScrub(PostgresScrub):
"""Extend to add session."""
@cached_property
def session(self):
"""Only fetch the session one time."""
return new_session()
Example class with decorator usage
class TestHandlerDatabaseRequired:
@TableScrub(table="table_name")
def test_handler_success(self, mock_datetime):
"""
Example of using the SetupTeardown ContextDecorator
with arbitrary setup and teardown.
"""
assert 1 == 1
# Effect the database test that may leave db in dirty state
Example function with decorator usage
@TableScrub(table="table_name")
def test_insert():
with TableScrub(setup=setup, teardown=teardown):
assert 1 == 1
# Effect the database test that may leave db in dirty state
Example function with context manager usage
def setup(self):
db.session.new_session().query(self.table).delete()
def teardown(self):
db.session.new_session().query(self.table).delete()
def test_insert():
with SetupTeardown(setup=setup, teardown=teardown):
assert 1 == 1
# Effect the database test that may leave db in dirty state
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
setup-teardown-0.0.5.tar.gz
(3.0 kB
view details)
Built Distribution
File details
Details for the file setup-teardown-0.0.5.tar.gz
.
File metadata
- Download URL: setup-teardown-0.0.5.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.0.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a32cd001a7340cd6a03c3eb4cf311479f24aa5f6516218079fbcf421710348d8 |
|
MD5 | e86e52a797d01e1044e369d5a28fb1f0 |
|
BLAKE2b-256 | 68849d2f305a9a3d5ea50f06834cc1f8f949e40072e43ccb43f5c6faebe5863a |
File details
Details for the file setup_teardown-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: setup_teardown-0.0.5-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.0.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c3f9f0a4b60bbf29741c31917abcc9ec7de8ecc2945f27e5b85dc88ee9cc172 |
|
MD5 | 862eec7a15348c3d3ee72e69c051f750 |
|
BLAKE2b-256 | 074df5d2ebf03483b60ac3c34af47f5477f1a9597f20544aafbe583e19c0f565 |