Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with starlette / fastapi TestClient #628

Open
johnraz opened this issue Jan 7, 2022 · 4 comments
Open

Compatibility with starlette / fastapi TestClient #628

johnraz opened this issue Jan 7, 2022 · 4 comments

Comments

@johnraz
Copy link

johnraz commented Jan 7, 2022

Hi!

I've been facing some issues with a test suite that makes use of Starlette's TestClient, which is also used by FastAPI.

Important note, I'm using pytest with pytest-recording.

There are 2 types of issues I see, and both are random and not easily reproducible:

  1. cassettes are sometimes not recorded when running the full test suite but are when running the test alone.
  2. tests are failing when running test2, and trying to access the cassette in test2, while test2 is not even using use_cassette... This mostly happens in parametrized tests but I'm not sure this is the "key" reason.

I think the problem mostly comes from the fact that the TestClient starts an async loop behind the scene which seems to hit the thread safety problem described here: #295, do you think it is indeed related?

Thanks for you time and for the otherwise very useful project 😃

@garbusbeach
Copy link

Hi, I've hit similar problem. Did you succeed to resolve this maybe?

@johnraz
Copy link
Author

johnraz commented Aug 1, 2024

No sadly not - it makes vcrpy hard to use with Starlette test client.

@mawkee
Copy link

mawkee commented Sep 9, 2024

I just hit the same problem. I'm convinced this is a problem with pytest-recording

@chris-erickson
Copy link

Seems to "work" for us, but tests that use the client (rather than testing some more direct python code) have this issue:
No match for the request (<Request (POST) http://testserver/orgs>) was found.

Was hoping this would suffice, but nope:
"ignore_hosts": ["testserver"],

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

No branches or pull requests

4 participants