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.2.tar.gz (12.0 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.2-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_loco_http-1.3.2.tar.gz
  • Upload date:
  • Size: 12.0 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.2.tar.gz
Algorithm Hash digest
SHA256 1fac7cfcc8cc25081ac8ef4f7bd835a1634f8af57cbb547b36107052a8c66123
MD5 ae9c2a945b03971e208698d38e550402
BLAKE2b-256 249117dda940c6d3b3c2d5d23c0fc38378e5c9640fd664fde8d9f2bc9e6f97d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_loco_http-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 14.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 07b24254a7b1a80a245558ec4029d9c28e96459da1bdd4381597f4bbb19ac28b
MD5 fd61f3bc062c7792cc46736e04c18606
BLAKE2b-256 44c899cba3905166a8540f6794ec665e405b83ba20c45452c74fca14d595549f

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