Building and Testing with Responder

Responder comes with a first-class, well supported test client for your ASGI web services: Requests.

Here, we’ll go over the basics of setting up a proper Python package and adding testing to it.

The Basics

Your repository should look like this:

Pipfile   Pipfile.lock

$ cat

import responder

api = responder.API()

def hello_world(req, resp):
    resp.text = "hello, world!"

if __name__ == "__main__":

$ cat Pipfile:

url = ""
verify_ssl = true
name = "pypi"

responder = "*"

pytest = "*"

python_version = "3.7"

allow_prereleases = true

Writing Tests

$ cat

import pytest
import api as service

def api():
    return service.api

def test_hello_world(api):
    r = api.requests.get("/")
    assert r.text == "hello, world!"

$ pytest:

========================== 1 passed in 0.10 seconds ==========================

(Optional) Proper Python Package

Optionally, you can not rely on relative imports, and instead install your api as a proper package. This requires:

  1. A proper file.
  2. $ pipenv install -e . --dev

This will allow you to only specify your dependencies once: in $ pipenv lock will automatically lock your transitive dependencies (e.g. Responder), even if it’s not specified in the Pipfile.

This will ensure that your application gets installed in every developer’s environment, using Pipenv.