-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
✅ Add the docs_src
directory to test coverage and update tests
#1904
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
657a447
:white_check_mark: Add tests related to
Kludex 42e8e73
fix more >:)
Kludex 5244b0a
:tada: Finish >:)
Kludex 25518dd
Merge remote-tracking branch 'origin/master' into fix/coverage
Kludex 549ecae
Readd tests to tests command
Kludex eafd26b
Merge remote-tracking branch 'origin/master' into fix/coverage
Kludex 20df532
Merge branch 'fix/coverage' of github.com:Kludex/fastapi into fix/cov…
Kludex 1fd3e43
Merge remote-tracking branch 'origin/master' into fix/coverage
Kludex b372943
Merge branch 'fix/coverage' of github.com:Kludex/fastapi into fix/cov…
Kludex 894e91b
📝 Tweak source examples for consistency and minimize changes
tiangolo addc8e3
📝 Update docs for Settings after a full review with the new code
tiangolo 0bc2378
⏪ Revert some changes in tests that are not strictly required
tiangolo b7228b7
✅ Update tests for settings after reverting modifications in examples
tiangolo 66e9c7f
✅ Add tests for missing coverage in examples
tiangolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
from fastapi import FastAPI | ||
|
||
from . import config | ||
from .config import settings | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get("/info") | ||
async def info(): | ||
return { | ||
"app_name": config.settings.app_name, | ||
"admin_email": config.settings.admin_email, | ||
"items_per_user": config.settings.items_per_user, | ||
"app_name": settings.app_name, | ||
"admin_email": settings.admin_email, | ||
"items_per_user": settings.items_per_user, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
from fastapi.testclient import TestClient | ||
from pytest import MonkeyPatch | ||
|
||
from docs_src.settings.app02 import main, test_main | ||
|
||
client = TestClient(main.app) | ||
|
||
|
||
def test_setting_override(): | ||
def test_settings(monkeypatch: MonkeyPatch): | ||
monkeypatch.setenv("ADMIN_EMAIL", "admin@example.com") | ||
settings = main.get_settings() | ||
assert settings.app_name == "Awesome API" | ||
assert settings.items_per_user == 50 | ||
|
||
|
||
def test_override_settings(): | ||
test_main.test_app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from docs_src.app_testing import test_main_b | ||
|
||
|
||
def test_app(): | ||
test_main_b.test_create_existing_item() | ||
test_main_b.test_create_item() | ||
test_main_b.test_create_item_bad_token() | ||
test_main_b.test_read_inexistent_item() | ||
test_main_b.test_read_item() | ||
test_main_b.test_read_item_bad_token() | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't duplicate the tests as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly, the tests from
docs_src
are not run by pytest, so the way to run them and have coverage for that is to do this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember doing what I did because before my changes the tests were running twice, and I think (I didn't check) this makes them run twice (those were your changes, just for context...), because (I think) the import is enough to make
pytest
find the tests. Anyway... 👀There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, maybe I have to review this again.
Although, one possible explanation is if you were running
pytest
and I was runningpytest tests
.But anyway, yeah, maybe for later. 😅