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

Add documentation about asynchronous testing (pytest-asyncio and httpx)#1619

Merged
tiangolo merged 15 commits intofastapi:masterfrom
empicano:add-documentation-about-testing-with-httpx
Aug 8, 2020
Merged

Add documentation about asynchronous testing (pytest-asyncio and httpx)#1619
tiangolo merged 15 commits intofastapi:masterfrom
empicano:add-documentation-about-testing-with-httpx

Conversation

@empicano
Copy link
Contributor

Addressing#1273 andKludex/starlette#652, I added a section about asynchronous testing via pytest-asyncio and httpx to the documentation. I also made a small note (+ link) in the beginner tutorial about it.

@codecov
Copy link

codecovbot commentedJun 24, 2020
edited
Loading

Codecov Report

Merging#1619 intomaster willnot change coverage.
The diff coverage is100.00%.

Impacted file tree graph

@@            Coverage Diff            @@##            master     #1619   +/-   ##=========================================  Coverage   100.00%   100.00%           =========================================  Files          236       237    +1       Lines         7073      7078    +5     =========================================+ Hits          7073      7078    +5
Impacted FilesCoverage Δ
tests/test_tutorial/test_async_tests/test_main.py100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last updated15556b...14c488b. Read thecomment docs.


@pytest.mark.asyncio
async def test_root():
async with AsyncClient(app=main.app, base_url='http://test') as ac:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You probably need to addtrust_env=False here as well, otherwise the async client might go through a proxy. Not sure if this is an upstream bug though.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

My initial thought was to simply follow theHTTPX example for calling into python web apps. Also, HTTPX setssome constraints on the proxies it accepts from the environment, I don't know if that changes anything.

Otherwise:

Suggested change
asyncwithAsyncClient(app=main.app,base_url='http://test')asac:
asyncwithAsyncClient(app=main.app,base_url='http://test',trust_env=False)asac:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

encode/httpx#1039 I think it might be a bug.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hm, interesting. What do you propose, we add thetrust_env=False for now?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, I think that's reasonable. Users who have some default network proxy active (e.g. for privacy reasons or in company network situations) will get some bizarre test failures.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hi there, chiming in to confirm that this odd behavior is indeed due to a bug in HTTPX.

So it might be okay to go with this as-is (i.e. without thetrust_env=False hack), keeping in mind thatencode/httpx#1039 looks to be fairly straight-forward to fix (in case anyone wants to give it a go - happy to review a PR, but no expectations of course), so hopefully a fix will be released soon and users equipped with proxies won't encounter this.

marco-neumann-by, empicano, and tiangolo reacted with thumbs up emoji
@empicano
Copy link
ContributorAuthor

@marco-neumann-by just to point out that the issue with httpx that we hung up on is resolved now

marco-neumann-by reacted with hooray emojitiangolo reacted with rocket emoji

@tiangolotiangolo merged commit2fd2843 intofastapi:masterAug 8, 2020
@tiangolo
Copy link
Member

Awesome! Great job@empicano ! Thanks for your contribution! 👏 📝 🤓 🍰

Thanks everyone for the discussion (and@florimondmanca for HTTPX 🚀 💙 ).

empicano reacted with rocket emoji

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

Reviewers

2 more reviewers

@florimondmancaflorimondmancaflorimondmanca left review comments

@marco-neumann-bymarco-neumann-bymarco-neumann-by left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@empicano@tiangolo@florimondmanca@marco-neumann-by

Comments


[8]ページ先頭

©2009-2026 Movatter.jp