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.

Install

> pip install pytest-loco-http

Requirements:

  • Python 3.13 or higher

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.3.tar.gz (12.1 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.3-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_loco_http-1.3.3.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.11 Linux/6.11.0-1018-azure

File hashes

Hashes for pytest_loco_http-1.3.3.tar.gz
Algorithm Hash digest
SHA256 e81c0c1afb63ff40356afdb23ff3037487df2111396075a7d9cd398b927886af
MD5 538e4e4ea0fae26c225358c9375a4e72
BLAKE2b-256 51d761c3c48e3690261a7a24eb8bacd82a4aba08ecbe39299f4ea84544d1df1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_loco_http-1.3.3-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.11 Linux/6.11.0-1018-azure

File hashes

Hashes for pytest_loco_http-1.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca2b0a8a932c7921dc8bcaed122efdb86e9d469464461e247d185be056cf1b6
MD5 38a447752b28ce9243d4cb048dddb250
BLAKE2b-256 f89890b46de874a1ecc1e24165a47c154999c2c4461c27a1592e7a220f6d53d5

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