1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
"""
A helper module to access the superclass'
setUp() and tearDown() methods of generated
test classes.
"""
import asyncio
class TestSetup:
def __init__(self, sup):
self.sup = sup
@property
def setup(self):
if hasattr(self.sup, "setup"):
return self.sup.setup
if hasattr(self.sup, "setUp"):
return self.sup.setUp
@property
def teardown(self):
if hasattr(self.sup, "teardown"):
return self.sup.teardown
if hasattr(self.sup, "tearDown"):
return self.sup.tearDown
def sync_before_each(self):
setup = self.setup
if setup:
return setup()
def sync_after_each(self):
teardown = self.teardown
if teardown:
return teardown()
async def async_before_each(self):
res = self.sync_before_each()
if res and asyncio.iscoroutine(res):
return await res
else:
return res
async def async_after_each(self):
res = self.sync_after_each()
if res and asyncio.iscoroutine(res):
return await res
else:
return res
|