Monkey Patching attribute
We can use the monkeypatch fixture to do the same.
- It stands out more as it is a fxture and you can search for the name
- It only applies to the current test function. So they are now independent again.
import app
def test_sum(monkeypatch):
monkeypatch.setattr(app, 'data_file', 'test_1.json')
res = app.get_sum()
assert True
assert res == 42
def test_again():
print(app.data_file) # it is now back to the original value