Last active
          April 18, 2018 07:20 
        
      - 
      
- 
        Save YanhaoYang/0c35ed968e6b0f1ab247fd9eff33eb17 to your computer and use it in GitHub Desktop. 
    Mock function indirectly with pytest
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def test_something(mocker): | |
| session = requests.Session() | |
| resp = requests.Response() | |
| resp._content = "response_body" | |
| resp.status_code = 200 | |
| resp2 = requests.Response() | |
| resp2._content = '{"results":[]}'.encode('utf-8') | |
| resp2.status_code = 200 | |
| mocker.patch.object(session, 'get', side_effect=[resp, resp2]) | |
| mocker.patch('requests.Session', return_value=session) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment