Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Replace Starlette's TestClient from `requests` to `httpx`! 🎉

License

NotificationsYou must be signed in to change notification settings

Kludex/bump-testclient

Repository files navigation

Package version

Starlette 0.21.0 changed theTestClient implementation: it replaced therequests library withhttpx.As those libraries have different APIs, this change break tests for Starlette's users.

Thiscodemod makes the transition to Starlette 0.21.0 easier.It makes the changes needed to make the tests work again.

Why?

Make your life easier. Suggested bySebastián Ramírez as a joke, but well... I did it.

Transformations

  1. Replaceclient.<method>(...) byclient.request("<method>", ...)

The methods ("delete", "get", "head", "options") doesn't accept thecontent,data,json andfiles parameters.

Conditions for this transformation:

  • Usingclient.<method> and<method> in ("delete", "get", "head", "options").
  • Usingcontent,data,json orfiles parameters.
  1. Replaceclient.<method>(..., allow_redirects=...) byclient.<method>(..., follow_redirects=...)

HTTPX usesfollow_redirects instead ofallow_redirects.

  1. Replaceclient.<method>(..., data=...) byclient.<method>(..., content=...)

If the argument passed todata is either text or bytes,content should be used instead.

Conditions for this to happen:

  • data parameter receives a bytes/text argument.

Installation

pip install bump-testclient

Usage

Run the following on the repository you want to format:

python -m bump_testclient<files>

You can also use the pre-commit. Add the following to your.pre-commit-config.yaml file:

  -repo:https://github.com/Kludex/bump-testclientrev:0.3.0hooks:      -id:bump_testclient

License

This project is licensed under the terms of the MIT license.

About

Replace Starlette's TestClient from `requests` to `httpx`! 🎉

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2026 Movatter.jp