Skip to content
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

Raise our own utcnow DeprecationWarning with the right stacklevel #486

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andersk
Copy link

@andersk andersk commented Oct 23, 2024

Previously, when time is mocked, no DeprecationWarning would be reported at all, and when time is not mocked, the original datetime.utcnow would misattribute its reported DeprecationWarning to the code of time_machine itself. Fix both cases to attribute the DeprecationWarning to the user code that called utcnow, by raising it ourselves with the right stacklevel, and test that we did so correctly.

Previously, when time is mocked, no DeprecationWarning would be
reported at all, and when time is not mocked, the original
datetime.utcnow would misattribute its reported DeprecationWarning to
the code of time_machine itself.  Fix both cases to attribute the
DeprecationWarning to the user code that called utcnow, by raising it
ourselves with the right stacklevel, and test that we did so
correctly.

Fixes adamchainz#445.

Signed-off-by: Anders Kaseorg <[email protected]>
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.

Deprecation warnings are silenced while time is mocked
1 participant