I has some function like this one:
URL = 'http://localhost:8080'
def func():
response = urlopen(URL)
return process(response)
And i want to test it with unittest. I do something like this:
from wsgiref.simple_server import make_server
def app_200_hello(environ,start_response):
stdout = StringIO('Hello world')
start_response("200 OK", [('Content-Type','text/plain')])
return [stdout.getvalue()]
s = make_server('localhost', 8080, app_200_hello)
class TestFunc(unittest.TestCase):
def setUp(self):
s.handle_request()
def test1(self):
r = func()
assert r, something
if __name__ == '__main__':
unittest.main()
At setUp() my tests are stoping because s.handle_request() wait for request. How i can go around that? Run s.handle_request() in another thread? or maybe there is another solutions?
EDIT: I want to test "func" function, not "app_200_hello"