Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Standalone WSGI server for running tests purpose.

Project description

Build Status Coverage Status

You can use wsgitest to start a HTTP server for a WSGI application and control the process:

@Request.application
def application(request):
    return Response('Hello World!')

class AppServerTestCase(TestCase):
    def test_hello_app(self):
        server = WSGITestServer.create(application)
        try:
            response = requests.get(server.application_url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content, b"Hello World!")
        finally:
            server.terminate()

    def test_hello_app_reference(self):
        server = WSGITestServer.create("tests.test_server.application")
        try:
            response = requests.get(server.application_url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content, b"Hello World!")
        finally:
            server.terminate()

The method WSGITestServer.create() initialize a multiprocessing.Process and wait for the server startup.

You can use server as a context manager to avoid that tests get stucked when you forget to “terminate” server:

@Request.application
def application(request):
    return Response('Hello World!')

class AppServerTestCase(TestCase):
    def test_hello_app(self):
        with WSGITestServer(application) as server:
            response = requests.get(server.application_url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content, b"Hello World!")

You can also start server with an specific host/ip or TCP port:

@Request.application
def application(request):
    return Response('Hello World!')

class AppServerTestCase(TestCase):
    def test_hello_app(self):
        with WSGITestServer(application, "0.0.0.0", 5000) as server:
            response = requests.get(server.application_url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content, b"Hello World!")

Project details


Release history Release notifications

This version
History Node

0.2.0

History Node

0.1.1

History Node

0.1.0

History Node

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
wsgitest-0.2.0.tar.gz (4.2 kB) Copy SHA256 hash SHA256 Source None May 28, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page