Skip to main content

http_testing framework on top of pytest

Project description


Test Package version Supported Python versions


This project aims to help to create e2e tests, by chaining http calls and verifications on target pages.


This project is built on pytest.

Each .py file in test represents several tests scenario on one target site, we can provide the site's hostname as a local variable, the framework know how to construct http call from that.

Each test function in the .py test file represent a scenario of test which is consisted by several steps. For example, test user's account page, first, we authenticate the client by post user's name and password, then access the account page to verify some values. Each step is described by calling the variable check which is a pytest fixture.



pip install pytest-httptesting

Create test suite

# test/
from http_testing.assertions import Assertions, NegativeAssertions
from http_testing.cookie import Cookie
from http_testing.page_checker import PageChecker
from http_testing.validators import Regex

host = ""  # mandatory: used in the `check` fixture
scheme = "https"  # "https" by default
port = None  # None by default

def test_scenario_one(check: PageChecker):
        title="Senario One",
            headers={"Content-Type": "text/html; charset=ISO-8859-1"},
            cookies=[Cookie(name="AEC", value=Regex(r".*"))],
            headers={"nooooo": ""},
            cookies=[Cookie(name="nop", value="a")],
        timeout=10,  # you can pass additional kwargs to httpx request

    assert check.previous_response.status_code == 200  # inspect previous response

Run test

$ pytest test --tb=no --no-header -v  # traceback is disabled because it is not very useful to anayse the functional error
============= test session starts =============
collected 1 item

test/ PASSED

============= 1 passed in 0.16s =============


In case of error, a temporary file will be generated, as shown in the short test summary info. It is a json file concluding response content, status code, headers and cookies.

$ pytest test --tb=no --no-header -v
============= test session starts =============
collected 1 item

test/ FAILED

============= short test summary info =============
FAILED test/ - AssertionError: Senario One - 'Content-Typessss':'text/html; charset=ISO-8859-1' not found in headers on page '' - please check file '/tmp/tmptaowd2u5'
============= 1 failed in 1.22s =============


Customize the http client configuration

It is possible to create a fixture http_client to create your own http client.

def http_client():
    with Client(verify=False, cookies={"cookie_1": "cookie_value_1"}) as client:
        yield client

Customize the base url

It is possible to create a fixture base_url to override the default construction of base url.

from httpx import URL
def base_url() -> URL:
    return URL("")

Project details

Download files

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

Source Distribution

pytest_httptesting-0.6.0.tar.gz (8.9 kB view hashes)

Uploaded source

Built Distribution

pytest_httptesting-0.6.0-py3-none-any.whl (13.5 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page