def custom_open(self, path: str, mode: str, *args, **kwargs):
        """
        If mode is for reading, use the real open,
        otherwise use a mock open.
        """
        if 'r' in mode and 'w' not in mode:
            return self.real_open(path, mode, *args, **kwargs)
        else:
            # For write mode, we'll use our global mock_open provided from the patch.
            return self.write_mock(path, mode, *args, **kwargs)

        If mode is for reading, use the real open,
        otherwise use a mock open.
        
tests/unit_tests/marqo/scripts/test_vespa_local.py