Noob in Python. Problem with fairly simple test case

Jason P. suscricions at
Wed Jul 15 13:44:22 CEST 2015

Hi all!

I'm working in a little Python exercise with testing since the beginning. So far I'm with my first end to end test (not even finished yet) trying to:

1) Launch a development web server linked to a demo app that just returns 'Hello World!'

2) Make a GET request successfully

I can't understand very well what's happening. It seems that the main thread gets blocked listening to the web server. My intent was to spawn another process for the server independent of the test. Obviously I'm doing something wrong. I've made several guesses commenting pieces of code (tearDown method for example) but I didn't manage to solve the problem(s).

I'm running the test through PyCharm. Python version = 3.4.3

Here it's the code:

import unittest
from tests.end_to_end.forecastserver import ForecastServer
import src.forecast.webservice as webservice
import requests

class TestForecastEndToEnd(unittest.TestCase):

    def setUp(self):
        # Start the forecast server
        self.server = ForecastServer()

    def tearDown(self):
        # Stop the forecast server

    def test_webservice_receives_a_request(self):
        response = requests.get('http://localhost:8000')

if __name__ == '__main__':

from wsgiref.simple_server import make_server
import multiprocessing

class ForecastServer:

    def __init__(self):
        self._httpd_process = None

    def start(self, webservice):
        if not self._httpd_process:
            httpd = make_server('localhost', 8000, webservice)
            self._httpd_process = multiprocessing.Process(

    def stop(self):
        if self._httpd_process:

        del self._httpd_process

def app(environ, start_response):
    status = '200 OK'
    headers = [('Content-type', 'text/plain')]
    start_response(status, headers)

    return ['Hello World!']

More information about the Python-list mailing list