What's advantage of a (default) function-scope fixture without teardown code? Why not just call the function at the beginning of the test?
For example, what's the benefit of writing:
@pytest.fixture
def smtp():
return smtplib.SMTP("smtp.gmail.com")
def test_ehlo(smtp):
response, msg = smtp.ehlo()
# ...
instead of simply:
def create_smtp():
return smtplib.SMTP("smtp.gmail.com")
def test_ehlo():
smtp = create_smtp()
response, msg = smtp.ehlo()
# ...
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).