Closely related: In python there is a good idiom for using context managers in setting / disabling .
I have a context manager that is used in tests to fix the time / time zone. I want it to be in pytest funcarg (or fixture, we use pytest2.2.3, but I can translate back). I could just do this:
def pytest_funcarg__fixedTimezone(request):
fixedTime = offsetTime.DisplacedRealTime(tz=' Australia/Brisbane')
def setup():
fixedTime.__enter__()
return fixedTime
def teardown(fixedTime):
fixedTime.__exit__(None, None, None)
... but it's a little bad. The linked Q jsbueno states: the problem is that your code does not have the right to call the method correctly __exit__if an exception occurs.
. pytest, - , . , pytest-y ? -, runtest hooks?