What's the benefit of a fixture with function scope and no teardown code? : <p>What's advantage of a (default) function-scope fixture without teardown code? Why not just call the function at the beginning of the test?</p>

<p>For example, what's the benefit of writing:</p>

<pre><code>@pytest.fixture
def smtp():
    return smtplib.SMTP("smtp.gmail.com")

def test_ehlo(smtp):
    response, msg = smtp.ehlo()
    # ...
</code></pre>

<p>instead of simply:</p>

<pre><code>def create_smtp():
    return smtplib.SMTP("smtp.gmail.com")

def test_ehlo():
    smtp = create_smtp()
    response, msg = smtp.ehlo()
    # ...
</code></pre>

<p>I understand why fixtures are useful when we need teardown code. I also understand why fixtures with scope other than function are useful: we may want to reuse the same "external" object in multiple tests (to save the time it takes to create it; or perhaps even to maintain its state -- although that seems to be rather dangerous since this creates an hard-to-see coupling between separate tests).</p>
