Python Mock open when there are multiple with open

Viewed 26
    def second():
        with open(path, 'r') as second_something:
            second_json = json.load(second_something)
    
    def first():
        second()
        with open(path, 'r') as first_something:
            first_json = json.load(first_something)
            
    
    @patch('builtins.open', new_callable=mock_open, read_data='{"hello":"yes"}')
    @patch('builtins.open', new_callable=mock_open, read_data='{"world":"no"}')
    def test_first(self):
        first()
        #doing asserting here
        assert(fist_json,{"world":"no"})

Writing a test case for "first" function and want to mock both "with open" statment, so wrote two @patch but both are getting '{"hello":"yes"}', instead of one getting '{"hello":"yes"}' and another '{"world":"no"}'. Having trouble with mocking this, please help me out.

0 Answers
Related