def test_again(): res = app.do_something() # it is still test_1.json ...
def test_app(): app.data_file = 'test_1.json' # manually overwrite res = app.do_something() # it is now test_1.json ...
def test_again(): res = app.do_something() # back to the original value ...
def test_sum(monkeypatch): monkeypatch.setattr(app, 'data_file', 'test_1.json') res = app.do_something() # It is now test_1.json ...
def test_sum(monkeypatch, tmpdir): fake_file = tmpdir.join('test_1.json') monkeypatch.setattr(app, 'data_file', fake_file) res = app.do_something() ...
import app app.do_something()
def test_something(): assert do_something()