Monkey Patching attribute

We can use the monkeypatch fixture to do the same.


exa/test_data_3.py
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