Replace deprecated datetime.utcnow() in test_nbf_token_in_future#579
Merged
Merged
Conversation
test_nbf_token_in_future built a future 'nbf' claim with datetime.utcnow(), deprecated since Python 3.12. The test module already imports timezone and uses timezone-aware datetimes elsewhere, so switch to datetime.now(timezone.utc) for consistency and to silence the deprecation warning. Test still passes (41 passed in test_decode_tokens.py).
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
test_nbf_token_in_futurebuilds a futurenbfclaim withdatetime.utcnow():datetime.utcnow()is deprecated since Python 3.12 and emits aDeprecationWarning. The test module already importstimezone(line 3) and uses timezone-aware datetimes elsewhere, so this is also an inconsistency.Fix
Use
datetime.now(timezone.utc), matching the module's existing convention.Verification
tests/test_decode_tokens.py— 41 passed.DeprecationWarning: datetime.datetime.utcnow() is deprecated ...; noutcnow()remains in the file.Test-only, one-line change.