Skip to content

Allow custom request predicates for runtime matching - #250

Open
edsonsims wants to merge 2 commits into
Colin-b:developfrom
edsonsims:feature/runtime-request-matchers
Open

edsonsims wants to merge 2 commits into
Colin-b:developfrom
edsonsims:feature/runtime-request-matchers

Conversation

@edsonsims

Copy link
Copy Markdown

An encoded request body currently cannot be decoded as part of selecting a mocked response. This implements the runtime matching requested in #200.

Add an optional match_request predicate receiving the fully read httpx.Request. It runs after the existing filters and composes with them. The same option works for response/callback/exception registration and request-history filtering, with synchronous and asynchronous HTTPX clients. The README includes a gzip-body example and documents synchronous boolean predicates, repeated evaluation, and error behavior.

Closes #200.

Validation on macOS, Python 3.12.14, pytest 9.1.1 and httpx 0.28.1:

  • The 22 new cases fail on the unchanged develop source and pass with this change.
  • Full suite: 368 passed, with 100% statement and branch coverage.
  • Black, Ruff, flake8, changed-file mypy, and whitespace checks pass.
  • Full-package mypy has four existing errors, reproduced on pristine develop; they are outside the changed files.

AI assistance: OpenAI Codex drafted the implementation and tests and performed automated review. All reported checks were run locally. Owner manual review and additional-platform validation are not claimed.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to match at runtime

2 participants