-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Bug: TestClient used in pytest fails with KeyError: 'session_maker_class'
#147
Comments
Heya, I do not think this is a bug but rather an issue with how you are using the test client fixture. @pytest.fixture()
def test_client() -> TestClient[Litestar]:
app.debug = True
return TestClient(app=app) That is your code, you are not using it as a yield based fixture. In your case (returning the client directly instead of yielding inside a context manager) does not emit the events and the key that it claims to be missing is only set when asgi events are sent (this only happens when you use it as a yield based fixture with context manager). The following is an example for a test client fixture in fastapi (the same applies for Litestar), if you can write your fixture this way for a Litestar app it should work. (If it doesn't then that is a bug 🙃) |
So it is... Thank you. I'll submit a PR against Litestar's documentation that shows examples of fixtures just like this. Is my PR adding a test for the example helpful? With this error fixed, it's catching another error with the |
thanks 😇
I will let other @jolt-org/maintainers and @jolt-org/members comment on that, I do not object to this 🙂 |
Hi - yes, it's definitely helpful. More coverage is always good! |
Well, the Litestar docs weren't wrong, I was just not reading carefully enough. Still, I opened this PR to improve them: litestar-org/litestar#3258 I'll update my PR on this repo as well, but close this issue since it's not a real issue. Thanks for the feedback! |
Description
I've developed a failing test by writing a test that tries to test the litestar example in this repo: main...sherbang:advanced-alchemy:litestar_test
URL to code causing the issue
https://github.com/sherbang/advanced-alchemy/tree/litestar_test
MCVE
# Your MCVE code here
Steps to reproduce
Screenshots
"In the format of:
![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)
"Logs
Jolt Project Version
0.8.1
Platform
Funding
The text was updated successfully, but these errors were encountered: