Skip to main content

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!")

Metadata

Release files for wsgitest 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wsgitest 0.2.0
File Size Uploaded
wsgitest-0.2.0.tar.gz 4.2 kB Details

Release files / wsgitest-0.2.0.tar.gz

Download URL wsgitest-0.2.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
06137e227d944837538d2d9a919c29fa31b9f4501337ca81827dd1a1b344e52c
BLAKE2b-256 checksum
How to use checksums
b09833d8053aab30d308d57e7c484cf6d4ed5a5ec3d15a73389f6c0e7c4ee25e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page