def test_side_effects_list(mock): mock.side_effect = [{1: 'a'}, {2: 'a'}, {3: 'a'}, {4: 'a'}] assert crazy.use_some_crazy_stuff(1) == {1: 'a'} assert crazy.use_some_crazy_stuff(1) == {2: 'a'} assert crazy.use_some_crazy_stuff(1) == {3: 'a'} assert crazy.use_some_crazy_stuff(1) == {4: 'a'}
def test_mock_requests(mock_get): d = {'biz': 'baz'} response = MagicMock() response.json.return_value = d mock_get.return_value = response assert crazy.use_some_crazy_stuff(1) == d
def test_side_effects(mock): mock.side_effect = lambda val: {val: 'a'} assert crazy.use_some_crazy_stuff(1) == {1: 'a'} assert crazy.use_some_crazy_stuff(2) == {2: 'a'} assert crazy.use_some_crazy_stuff('pie') == {'pie': 'a'}
def test_use_crazy_stuff_1(mock): d = {'foo': 'bar'} mock.return_value = d assert crazy.use_some_crazy_stuff(1) == d
def test_do_something_with_monkeypatch(monkeypatch): monkeypatch.setattr(crazy, 'do_some_crazy_stuff', lambda val: {val: 'a'}) assert crazy.use_some_crazy_stuff(1) == {1: 'a'} assert crazy.use_some_crazy_stuff(2) == {2: 'a'} assert crazy.use_some_crazy_stuff(3) == {3: 'a'}