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.
Usage
class PgSetupTeardown(ContextDecorator):
def __init__(self, table, **kwargs):
self.table = table
self.__dict__.update(kwargs)
def __enter__(self):
self.session = db.session.new_session()
self.session.query(self.table).delete()
self.session.commit()
return self
def __exit__(self, typ, val, traceback):
self.session = db.session.new_session()
self.session.query(self.table).delete()
self.session.commit()
class TestHandlerDatabaseRequired:
@SetupTeardown(table="table_name")
def test_handler_success(self, mock_datetime):
"""
Example of using the SetupTeardown ContextDecorator with arbitrary setup and teardown
"""
# execute the test
pass
def setup(self):
print("setup")
self.start_time = time.time()
def teardown(self):
print("teardown")
print("{}".format(time.time() - self.start_time))
# decorator application example
print("=============== Decorator Usage ===================")
@SetupTeardown(setup=setup, teardown=teardown)
def foo():
print("inner")
foo()
print("=============== Context Manager Usage ===================")
# contest manager application example
with SetupTeardown(setup=setup, teardown=teardown):
print("inner")
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.2.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for setup_teardown-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4726c845b0410639cf3e23da5dbf962c28e13d864ee77689168722ed98e3533f |
|
MD5 | b6b2eb642a3d6ecee6c57be53102fc26 |
|
BLAKE2b-256 | f7c18373c1e712d634dd830f74be19a649cf58a0686c62b113dcd48ffdb5ba86 |