1

how to mock the following using MagicMock in Python 2.6.6:

with open('filename.txt', 'rb') as f:
    json.dumps(json.load(f))
Santhosh Balasa
  • 170
  • 2
  • 11

2 Answers2

1

Yay, I found the solution, this is my approach:

@patch("json.load", MagicMock('{cool}')
@patch("json.dumps", MagicMock(return_value='{cool}'))
Santhosh Balasa
  • 170
  • 2
  • 11
0

You can use mock framework (install it by pip). Use patch and mock_open by following this answer.

Community
  • 1
  • 1
Michele d'Amico
  • 19,631
  • 8
  • 62
  • 71