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
Decorator Usage
Custom Database Class
from setup_teardown import SetupTeardown
class PgSetupTeardown(SetupTeardown):
def setup(self):
# Perform test setup
self.session = db.session.new_session()
self.session.query(self.table).delete()
return self
def teardown(self, typ, val, traceback):
# Perform test teardown
self.session.query(self.table).delete()
Example test with decorator usage
class TestHandlerDatabaseRequired:
@PgSetupTeardown(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 test 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()
# context manager application example
with PgSetupTeardown(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.4.tar.gz
(2.8 kB
view hashes)
Built Distribution
Close
Hashes for setup_teardown-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60324dcf0615abea6c811eff2d115bb50572ade2f895ed6339c9acc4d12ef1a1 |
|
MD5 | e9ce0bedd2d2e537358f2efdb74dd11b |
|
BLAKE2b-256 | d9dfd3485c9d1051f75f47455001c304b8b1e67fd03a20906ba09469532e3036 |