Skip to content

Test Client

Dawid Kraczkowski edited this page Feb 27, 2021 · 1 revision

Test client is a small utility class to simplify end to end testing of your application. If you are using pytest library it is recommended to create a mock, like below:

testconf.py

import chocs
import my_application

@pytest.fixture
def test_client() -> chocs.TestClient:
    client = TestClient(my_application.app)

    return client

Example request to an endpoint

import chocs

def test_get_request(test_client: chocs.TestClient) -> None:
  response = test_client.get("/users?id=12")
  assert response.status_code is chocs.HttpStatus.OK

Clone this wiki locally