mardi 6 mars 2018

how to mock session in Python's request library?

I have been trying to figure out how exactly to mock the session of Python's request library but couldn't find a solution till now. Here's my code of common.py that i need to write a test for:

import requests

def request_url(method, url):
    return _request_url(method, url)

def _request_url(method, url):
    session = requests.session()
    adapter = TlsAdapter(ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1)
    session.mount("https://", adapter)
    return response = session.request(method, url)

Any help would be appreciated! Thanks!

Aucun commentaire:

Enregistrer un commentaire