On Sunday 5 May 2013 at 15:05, holger krekel wrote:
> after having been asked by Andreas Pelme and Vladimir Keleshev, repeatedly,
> i finally tried to allow fixture functions to be context managers like this:
> @pytest.fixture
> def myfixture():
> print "setup"
> yield val
> print "teardown"
I just want to note that this makes it very easy to reuse/combine existing
context managers as fixtures:
@pytest.fixture
def myfixture():
with context_manager_a():
with context_manager_b() as foo:
yield foo
This is my main use case for this, those kinds of setups would be cumbersome to
write with addfinalizer().
> feedback welcome, actually without people actively
> wanting it, it might be thrown out again ;)
I just replaced my pytest-contextfixture's with this, and everything just works
(that uses the above pattern)!
I also changed some of my fixtures which previously used
request.addfinalizer(), and it just worked too. It really makes fixture
definitions very nice to read and write IMHO!
Thanks a lot for looking into this Holger! I really hope it is not getting
throwed out! :)
Andreas
_______________________________________________
Pytest-dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pytest-dev