Skip to content

Comments

Add bake() method for pre-configured request expectations#470

Merged
csernazs merged 1 commit intocsernazs:masterfrom
HayaoSuzuki:feat/stackable-expectations
Feb 12, 2026
Merged

Add bake() method for pre-configured request expectations#470
csernazs merged 1 commit intocsernazs:masterfrom
HayaoSuzuki:feat/stackable-expectations

Conversation

@HayaoSuzuki
Copy link
Contributor

@HayaoSuzuki HayaoSuzuki commented Feb 10, 2026

Add HTTPServer.bake(**kwargs) which returns a BakedHTTPServer proxy with pre-configured defaults for expect_request() and related methods.

  • BakedHTTPServer is a lightweight proxy, such that no new server is created.
  • Defaults use last-wins merging, such that call-time kwargs override baked defaults.
  • bake() can be chained, such that httpserver.bake(method="POST").bake(headers={...}) .
  • All three expect_* methods are supported.
  • Other attributes (url_for, check_assertions, etc.) are delegated via __getattr__ .
  • Context manager protocol is supported via explicit __enter__ and __exit__ delegation.

Closes #46

@HayaoSuzuki HayaoSuzuki force-pushed the feat/stackable-expectations branch 2 times, most recently from 7677b29 to 88a9339 Compare February 10, 2026 15:05
@csernazs
Copy link
Owner

Thanks for the PR, I submitted my comments

@HayaoSuzuki
Copy link
Contributor Author

Thanks for the review. I submitted fix commits. Feel free to check them when you have time.

@HayaoSuzuki HayaoSuzuki marked this pull request as ready for review February 11, 2026 09:55
@HayaoSuzuki HayaoSuzuki force-pushed the feat/stackable-expectations branch from b6c5051 to 5897e6d Compare February 11, 2026 19:06
@csernazs
Copy link
Owner

may I ask you to write a release notes for this? You can run .venv/bin/reno new --edit stackable-expectations and then write a short text in yaml. Feel free to add your github handle there as you implemented the whole thing.

If you don't want, I can do that as well.

@csernazs
Copy link
Owner

hi @HayaoSuzuki ,

Thanks for all the changes, I think everything looks great.

Could you please squash your commits?

Then I'm happy to merge it.

Zsolt

- Extract to separate module and fix nested context manager
- Add RequestMatcherKwargs TypedDict
- Add release note of bake() method and BakedHTTPServer proxy
@HayaoSuzuki HayaoSuzuki force-pushed the feat/stackable-expectations branch from 821f1b0 to 6f102e3 Compare February 12, 2026 07:51
@HayaoSuzuki
Copy link
Contributor Author

HayaoSuzuki commented Feb 12, 2026

@csernazs I squashed some commits. Thanks for the gracious review of our PR.

@csernazs csernazs merged commit 310529c into csernazs:master Feb 12, 2026
10 checks passed
@HayaoSuzuki HayaoSuzuki deleted the feat/stackable-expectations branch February 12, 2026 09:01
@csernazs
Copy link
Owner

hi @HayaoSuzuki ,

This has been released with version 1.1.5.

Thanks for the implementation again,
Zsolt

github-actions bot added a commit to paulstaab/headless-rss that referenced this pull request Feb 16, 2026
Bumps [pytest-httpserver](https://github.com/csernazs/pytest-httpserver)
from 1.1.4 to 1.1.5.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/csernazs/pytest-httpserver/releases">pytest-httpserver's
releases</a>.</em></p>
<blockquote>
<h2>1.1.5</h2>
<h2>What's Changed</h2>
<ul>
<li>Add <code>bake()</code> method for pre-configured request
expectations by <a
href="https://github.com/HayaoSuzuki"><code>@​HayaoSuzuki</code></a> in
<a
href="https://redirect.github.com/csernazs/pytest-httpserver/pull/470">csernazs/pytest-httpserver#470</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/csernazs/pytest-httpserver/compare/1.1.4...1.1.5">https://github.com/csernazs/pytest-httpserver/compare/1.1.4...1.1.5</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/csernazs/pytest-httpserver/blob/master/CHANGES.rst">pytest-httpserver's
changelog</a>.</em></p>
<blockquote>
<h1>1.1.5</h1>
<p>.. _Release Notes_1.1.5_New Features:</p>
<h2>New Features</h2>
<ul>
<li>Add <code>bake()</code> method to <code>HTTPServer</code> for
creating pre-configured
request expectation proxies (<code>BakedHTTPServer</code>). This allows
sharing
common keyword arguments (e.g. <code>method</code>,
<code>headers</code>) across multiple
<code>expect_request()</code> calls with last-wins merging semantics.
<code>[#470](csernazs/pytest-httpserver#470)
&lt;https://github.com/csernazs/pytest-httpserver/pull/470&gt;</code>_
Contributed by <code>@HayaoSuzuki
&lt;https://github.com/HayaoSuzuki&gt;</code>_</li>
</ul>
<p>.. _Release Notes_1.1.4:</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/840c7d108cf045e0309fa52543cd7d2def52b1bb"><code>840c7d1</code></a>
CHANGES.rst: add release notes for 1.1.5</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/7c7be887f740473ba5ca4b73ed92fa3fd2c3f446"><code>7c7be88</code></a>
Version bump to 1.1.5</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/f1971ce844a397a8c06c8f5fabd166c67b7caf87"><code>f1971ce</code></a>
fix-release: remove release notes</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/ae956c0cbe81ce09b5591250b7a297a5d3a758c0"><code>ae956c0</code></a>
release.py: fix check order</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/c8804805cfc59f82fcd38a11e88a6c7b98df8609"><code>c880480</code></a>
Make release.py more robust</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/310529cfa618ab061eb40c9fd9335b51a9f9fd40"><code>310529c</code></a>
Add bake() method for pre-configured request expectations</li>
<li><a
href="https://github.com/csernazs/pytest-httpserver/commit/7716cda169ffd9fd5215b18887fa09fa80ba6199"><code>7716cda</code></a>
[pre-commit.ci] pre-commit autoupdate</li>
<li>See full diff in <a
href="https://github.com/csernazs/pytest-httpserver/compare/1.1.4...1.1.5">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pytest-httpserver&package-manager=uv&previous-version=1.1.4&new-version=1.1.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>
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.

Stackable expectations

2 participants