-
-
Notifications
You must be signed in to change notification settings - Fork 397
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
docs: Fix testing code examples #3143
Conversation
Could you explain a bit more what exactly is being fixed here? The purpose of the examples being in self-contained files instead of inline is that they can be automatically tested as part of our test suite and typed checked. |
Thanks for the explanation @hugovk, makes sense. I think the idea here was that example files should be self-contained, which is why all the code was copied into one file. Of course that doesn't make sense here given the text. I see two ways to fix this: Either stick to "one self-contained file" and remove the I'm actually leaning towards option 1 slightly, because the import pytest
from litestar.status_codes import HTTP_200_OK
from litestar.testing import TestClient
from typing import Generator
from my_app.main import app
@pytest.fixture()
def client() -> Generator[TestClient, None, None]:
with TestClient(app=app) as client:
yield client
def test_health_check(client: TestClient):
response = client.get("/health-check")
assert response.status_code == HTTP_200_OK
assert response.text == "healthy" and the text be adjusted accordingly. |
Option 1 sounds fine. Like you say, the main point is you can put the client in a fixture for re-use, and you can put that where you like (same file or (Apologies for the force-push, I forgot this PR is off my |
@guacs I think this still needs the changes discussed 👀 |
Oh I think I misunderstood then :P I thought the changes were fine since it showed that you can use the test client as a fixture, but now looking at it again I think you may be right. I think you wanted to make the change so that we remove the reference to |
That's what I thought @kedod was agreeing to here:
It also still has the in-line code, which we don't test. |
You're right. Also, did you mean @hugovk? |
There are still some changes that need to be made.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3143 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 320 320
Lines 14445 14425 -20
Branches 2298 2322 +24
=======================================
- Hits 14190 14171 -19
Misses 113 113
+ Partials 142 141 -1 ☔ View full report in Codecov by Sentry. |
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3143 |
I'll close this because it needs rewriting another way, and this is from my |
Description
tests/conftest.py
, and the production code is still inmy_app/main.py
, so we just need the test case intests/test_health_check.py
.