In many application we can find hard-coded pathes. In order to test them we will need to create that exact path which is not always easy. This also means we cannot run two tests at the same time with different content in those files. (The actual "application" is just adding numbers together.)
import json data_file = "/corporate/fixed/path/data.json" def get_sum(): with open(data_file) as fh: data = json.load(fh) # ... result = data['x'] + data['y'] return result
import app def test_sum(): res = app.get_sum() assert True
def get_sum(): > with open(data_file) as fh: E FileNotFoundError: [Errno 2] No such file or directory: '/corporate/fixed/path/data.json'