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.gethttp.posthttp.puthttp.patchhttp.deletehttp.headhttp.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 statusheaders- normalized response headers (lowercase keys)cookies- list of structured cookiesbody- raw response body (bytes)text- response body as textrequest- structured original requesthistory- 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.bodyas bytesrequest.textas text
Files
Multipart file uploads are supported via the files field.
Each file entry defines:
name— form field namecontent— string or bytesfilename(optional)mimetype(optional)
If mimetype is not provided, it is inferred:
application/octet-streamfor bytestext/plainfor 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c65b0c480492e157b5e9633240390b58c24d84805a77a912ad53996bc782a4b
|
|
| MD5 |
e46f93f94b24ed20ba18254d0c4847c4
|
|
| BLAKE2b-256 |
147f4009df81961fbda2d64b5e2cb27d22170b150f475c9fa1d6c077195f4145
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
503d2a3514f16c63be29e3c13aa1d850858a432e76db06bdfa359e0b9d7f1bfa
|
|
| MD5 |
492ef5417bf8c9fa1cadf9b4140b6678
|
|
| BLAKE2b-256 |
33e129d6f1dc07508273337d89a9c45bfa365ad148380f9e0cf0afa2c0a72785
|