Hey Vladimir, thanks for your considerations (relating to http://pytest.org/dev/yieldfixture.html ) I am going to write a condensed reply to the few points where i disagree. TLDR, i suggest to go for ``yield_fixture`` for pytest-2.4. On Sat, Sep 28, 2013 at 22:29 +0200, Vladimir Keleshev wrote:
Now, to comment on disadvantages: Yield-style fixtures present us with a superset of functionality of what return-style fixtures can achieve. I would even like to say that except for backwards-compatibility and user habit concerns, there is no need for return-style fixtures at all, if yield-style is available. So I would even argue that yield-style fixtures should take the main place in fixture documentation, and return-style fixtures mentioned for backwards compatibility (as funcargs are).
We can discuss this for 2.5 but not for 2.4. It's too massive a change at this point. Also, from giving courses to non-expert Pythonistas i know that "yield" (as much as inheritance and other concepts) are not easy concepts if if they are in computer science.
4.2 There is a high chance (in my experience) of mistyping `return` for `yield` like:
@fixture def db(): db = DB() return db db.clear()
Even worse, this fixture could still appear to work, until some later time, when they system runs out of file descriptors, for example.
I think this error is highly unlikely because "return" for almost everybody marks the end of the function. So for pytest-2.4 we are left with a choice between a new "yield_fixture" decorator or passing a ``yieldctx=True`` to the existing one. To make it easier for people to use yield fixtures everywhere a decorator might be preferable. You could write: from pytest import yield_fixture as fixture and use yield style everywhere. Not using yield in a yield_fixture then would get you an error. Using yield in a @pytest.fixture would work as before. Originally i didn't want to go with a separate decorator because it duplicates API and docstrings. But maybe this can be mediated by just saying "same as pytest.fixture but use 'yield' instead of 'return" for providing a fixture instance, see http:/... for details." Sounds like a plan? holger