jeudi 30 novembre 2017

mock python http requests for testing and development

I am using python "requests" and it works great, but now I want to be able to "mock" responses instead of touching the real servers.

I am doing this:

r = requests.get(self.url+'/somepath', params=payload)

In guzzlephp I could do this:

$mock = new MockHandler([
    new Response(200, ['X-Foo' => 'Bar'], 'mocked response')
]);

$handler = HandlerStack::create($mock);

$client = new Client(['handler' => $handler]);

is there something similar here in requests or in python?

Thanks!

Aucun commentaire:

Enregistrer un commentaire