monkeypatch location from target (can be class/module/function or string which is taken as importable python path) examples: monkeypatch.replace(os.path.abspath, lambda x: "") monkeypatch.replace("requests.get", ...)