fork download
  1. import sys
  2. # your code goes hereimport sys
  3. print("Python version")
  4. print (sys.version)
  5.  
  6. def f1():
  7. a = 'do not make this when f1() is mocked'
  8. print("should be printed once")
  9. return 10, True
  10.  
  11. def f2():
  12. num, stat = f1()
  13. return 2*num, stat
  14.  
  15. import mock
  16.  
  17. print f2() # Unchanged f1 -> prints (20, True)
  18.  
  19. with mock.patch('__main__.f1') as MockClass: # replace f1 with MockClass
  20. MockClass.return_value = (30, True) # change the return value
  21. print f2() # prints now 60,
Success #stdin #stdout 0.03s 10104KB
stdin
Standard input is empty
stdout
Python version
2.7.16 (default, Apr  6 2019, 01:42:57) 
[GCC 8.3.0]
should be printed once
(20, True)
(60, True)