Given a test file as follows...
(taken from the example at https://docs.pytest.org/en/latest/fixture.html)
test_with_fixture.py
import pytest
@pytest.fixture
def smtp_connection():
import smtplib
return smtplib.SMTP("smtp.gmail.com", 587, timeout=5)
I guess this is an over simplified example, but what is the benefit of declaring the smtp connection int his way as opposed to...
test_without_fixture.py
import smtplib
smtp_connection = smtplib.SMTP("smtp.gmail.com", 587, timeout=5)
In the test I am writing at present I have a lot of static values e.g.
expected_result_of_calculation = 10
(etc)
Some of these are more complex data structures including dictionaries and lists.
Should I declare these as fixtures or just have them in the global scope of my test file?
I'm guessing that fixtures are more useful when you want to generate test inputs through code and have the fixture just return that? This would encapsulate the generation of that data. But for static data as I have? Are they needed?