-
-
Notifications
You must be signed in to change notification settings - Fork 902
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
Stop using datetime.utcnow() in tests #1308
Conversation
90d6e72
to
172e239
Compare
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.
Thanks! As this is a bug fix, could you make it off the latest 3.x branch, per https://github.com/pallets-eco/flask-sqlalchemy/blob/main/CONTRIBUTING.rst#start-coding ?
tests/test_model.py
Outdated
@@ -14,6 +15,11 @@ | |||
from flask_sqlalchemy.model import Model | |||
|
|||
|
|||
class UTCNow(datetime): |
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.
Rather than making this a subclass with a tricky __new__
, this should just be a function:
def now() -> datetime:
return datetime.now(timezone.utc)
172e239
to
5bd2d07
Compare
5bd2d07
to
ed32fa1
Compare
I have addressed both comments, thanks! |
datetime.utcnow() is deprecated for Python 3.12+, and raises a warning. Since warnings are treated as errors, this results in test failures. Since utcnow calls are done by the SQLAlchemy mapping machinery, we need to use a function. Fixes pallets-eco#1303
ed32fa1
to
2cbf3f2
Compare
@davidism Thanks, I've reverted that bit. |
Sorry, completely forgot about this PR and ended up fixing it myself when doing some updates. Thanks for working on it! |
datetime.utcnow() is deprecated for Python 3.12+, and raises a warning. Since warnings are treated as errors, this results in test failures. Since utcnow calls are done by the SQLAlchemy mapping machinery, we need to use a callable.
Fixes #1303
Checklist:
CHANGES.rst
summarizing the change and linking to the issue... versionchanged::
entries in any relevant code docs.pre-commit
hooks and fix any issues.pytest
andtox
, no tests failed.