[Python] Mockare aiohttp per tests

Manlio Perillo manlio.perillo a gmail.com
Ven 7 Ago 2015 17:42:32 CEST


2015-08-07 16:50 GMT+02:00 flandero <flandero a gmail.com>:

> Ciao,
> sto usando una library per mockare su requests, chiamata httpretty. Un
> codice tipo questo:
>
> import httpretty
> import requests
> @httpretty.httprettified
> def prova():
>   httpretty.register_uri(method=httpretty.POST,uri='http://url/',body='ciao
> ciao')
>   requests.post('http://url/', data={'a': 1})
>   print(httpretty.last_request().body)
>
> Molto bello, e rende testabili componenti che altrimenti non lo sarebbero.
>
>
Io quando devo testare un client HTTP lancio un server WSGI in un processo
separato (multiprocessing),
utilizzando una Queue per la comunicazione.

> [...]

Ciao  Manlio
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20150807/c97e3060/attachment.html>


Maggiori informazioni sulla lista Python