Skip to main content

HTTP support for pytest-loco

Project description

pytest-loco-http

HTTP support for pytest-loco.

The pytest-loco-http extension provides first-class HTTP support for the pytest-loco DSL. It introduces a set of HTTP actors (http.get, http.post, http.put, http.delete, etc.) that execute real HTTP requests using managed sessions and return normalized, structured response objects.

Requests

Each HTTP method is exposed as an actor:

  • http.get
  • http.post
  • http.put
  • http.patch
  • http.delete
  • http.head
  • http.options

Every actor accepts a common set of parameters and produces a normalized response object in the execution context.

For example:

title: Simple GET request
action: http.get
url: https://httpbin.org/get
timeout: 30
expect:
  - title: Status is 200
    value: !var result.status
    match: 200

Sessions are managed automatically. You may optionally specify a logical session name (default by default).

Responses

Response fields include:

  • status - HTTP status
  • headers - normalized response headers (lowercase keys)
  • cookies - list of structured cookies
  • body - raw response body (bytes)
  • text - response body as text
  • request - structured original request
  • history - redirect chain (list of responses)

For example:

...
expect:
  - title: Response contains expected text
    value: !var result.text
    regexMatch: httpbin\.org
    multiline: yes

Redirect history can be inspected:

...
export:
  firstRedirect: !var result.history.0

Query parameters

Query parameters can be passed using the params field (aliases: query, queryParams).

action: http.get
url: https://httpbin.org/get
params:
  test: "true"
expect:
  - title: Query is echoed
    value: !var result.text
    regex: \?test=true
    multiline: yes

Query parameters are automatically encoded and appended to the URL.

Data

The data field allows sending raw request bodies as str or bytes.

---
action: http.post
url: https://httpbin.org/post
data: |
  {"message": "hello"}
headers:
  content-type: application/json
expect:
  - title: Status is 200
    value: !var result.status
    match: 200

The raw body is preserved in the response model as:

  • request.body as bytes
  • request.text as text

Files

Multipart file uploads are supported via the files field.

Each file entry defines:

  • name — form field name
  • content — string or bytes
  • filename (optional)
  • mimetype (optional)

If mimetype is not provided, it is inferred:

  • application/octet-stream for bytes
  • text/plain for strings

Binary file

action: http.post
url: https://httpbin.org/post
files:
  - name: test
    content: !binaryHex |
      48 65 6C 6C 6F 2C 20
      57 6F 72 6C 64 21
expect:
  - title: Status is 200
    value: !var result.status
    match: 200

Text file

action: http.post
url: https://httpbin.org/post
files:
  - name: test
    content: Hello, World!
expect:
  - title: File content is echoed
    value: !var result.text
    regex: '"Hello, World!"'
    multiline: yes

Instructions

Provide !urljoin instruction that compose a URL at runtime by joining a base URL from the DSL context with a postfix path.

This instruction is useful when endpoints depend on previously resolved values (e.g. environment-specific base URLs, dynamically returned URLs, or configuration variables).

Syntax:

!urljoin <variable> <postfix>
  • <variable> — name of a context variable containing a base URL;
  • <postfix> — relative path segment to append to the base URL.

Both parts must be separated by whitespace.

For example:

...
vars:
  baseUrl: https://api.example.com
action: http.get
url: !urljoin baseUrl api/v1/users
...

Resulting URL at runtime: https://api.example.com/api/v1/users

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_loco_http-1.3.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_loco_http-1.3.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_loco_http-1.3.1.tar.gz.

File metadata

  • Download URL: pytest_loco_http-1.3.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.12 Linux/6.14.0-1017-azure

File hashes

Hashes for pytest_loco_http-1.3.1.tar.gz
Algorithm Hash digest
SHA256 3c65b0c480492e157b5e9633240390b58c24d84805a77a912ad53996bc782a4b
MD5 e46f93f94b24ed20ba18254d0c4847c4
BLAKE2b-256 147f4009df81961fbda2d64b5e2cb27d22170b150f475c9fa1d6c077195f4145

See more details on using hashes here.

File details

Details for the file pytest_loco_http-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_loco_http-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.12 Linux/6.14.0-1017-azure

File hashes

Hashes for pytest_loco_http-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 503d2a3514f16c63be29e3c13aa1d850858a432e76db06bdfa359e0b9d7f1bfa
MD5 492ef5417bf8c9fa1cadf9b4140b6678
BLAKE2b-256 33e129d6f1dc07508273337d89a9c45bfa365ad148380f9e0cf0afa2c0a72785

See more details on using hashes here.

Supported by

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