Skip to content

Replace deprecated datetime.utcnow() in test_nbf_token_in_future#579

Merged
vimalloc merged 1 commit into
vimalloc:mainfrom
Sanjays2402:fix/test-utcnow-deprecation
Jul 2, 2026
Merged

Replace deprecated datetime.utcnow() in test_nbf_token_in_future#579
vimalloc merged 1 commit into
vimalloc:mainfrom
Sanjays2402:fix/test-utcnow-deprecation

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Summary

test_nbf_token_in_future builds a future nbf claim with datetime.utcnow():

date_in_future = datetime.utcnow() + timedelta(seconds=30)

datetime.utcnow() is deprecated since Python 3.12 and emits a DeprecationWarning. The test module already imports timezone (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.

date_in_future = datetime.now(timezone.utc) + timedelta(seconds=30)

Verification

  • tests/test_decode_tokens.py41 passed.
  • Confirmed the old call emits DeprecationWarning: datetime.datetime.utcnow() is deprecated ...; no utcnow() remains in the file.

Test-only, one-line change.

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).
@vimalloc vimalloc merged commit 645dad0 into vimalloc:main Jul 2, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants