{{ message }}
Repository navigation
Conversation
Member
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
FastAPI's security schemes each ship paired tests:
test_security_<scheme>.py(defaultauto_error=True) andtest_security_<scheme>_optional.py(auto_error=False).OAuth2AuthorizationCodeBearerwas missing its_optionaltest which is precisely whyfastapi/security/oauth2.pycarried a# pragma: nocoveron thereturn Nonebranch of its__call__.Its sibling
OAuth2PasswordBearerhas the identical branch without a pragma, because it is already covered bytest_security_oauth2_password_bearer_optional.py.This PR closes that gap: it adds the missing optional test and removes the now-redundant coverage-exclusion, making the two schemes consistent and the optional-auth path genuinely tested.
Changes (two tiny, atomic commits)
test:addtests/test_security_oauth2_authorization_code_bearer_optional.py(5 tests) anonymous request, valid bearer, non-bearer scheme (drives thereturn Nonebranch), whitespace bearer, and aninline_snapshotOpenAPI assertion encoding theauthorizationCodeflow. Modeled on the existing password-bearer-optional test.refactor:drop the stale# pragma: nocoverfrom thereturn Noneline inOAuth2AuthorizationCodeBearer.__call__. One line, no logic change; the branch is now exercised by real tests.The test that justifies the pragma removal lands first, so no commit in history has an untested-but-un-pragma'd branch.
Testing
return None) is no longer in the Missing set, while line 647 (theauto_error=Trueraise, covered by the non-optional file) still is confirming the new test hits the exact branch whose pragma was removed.ruff checkandruff format --checkclean.Risk / trade-offs
Essentially none no production logic changed (single-line comment removal); purely additive test + coverage hygiene.