I learned about the benefits of test-based development and am trying to develop my first TDD application using pytest and the setuptools parameter develop. Still good. One question I have is: where should resources be imported that should be tested in my modules test_*?
For example, I could import at the module level:
from app.module1 import resource1, resource2
def test_resource1():
assert test_resource1 == "expected value 1"
def test_resource2():
assert test_resource2 == "expected value 2"
On the other hand, it seems that it makes sense to import in each test function:
def test_resource1():
from app.module1 import resource1
assert test_resource1 == "expected value 1"
def test_resource2():
from app.module1 import resource2
assert test_resource2 == "expected value 2"
This, of course, assumes that the resources that need to be tested are no longer needed.
Besides the differences in the required characters for input, is there an advantage to doing this or that?