MPP-3487 - Fix tests, handle missing sqlcommenter in Python 3.12, #4724
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.
This makes changes needed for tests to run under Python 3.12, with no deprecation warnings.
Mock that doesn't do what was intended
For
test_grab_keyfile_checks_cert_url_origin
, the lineraises an exception:
This is a new check for mock functions which are similar to the mock assertion functions. The developer probably intended:
However, this also fails. It would be a bit of work to make this pass, requiring mocking the return of a valid PEM. After a bit of reading, I re-wrote as:
and called it after the
SuspiciousOperation
was raised.LogRecord has new attribute
taskName
This attribute was added to log the asyncio task name, python/cpython#91513 . The
log_extra
helper needs to ignore it.utcnow()
is finally going awaydatetime.utcnow() is one of the gotcha methods. It returns a
datetime
in UTC time, but without timezone information. Django will catch this if you try to store in a model, but some of our test code still uses it. It now raises aDeprecationWarning
. I've replaced this code withdatetime.now(UTC)
, which returns a timezone-aware datetime.google-cloud-sqlcommenter doesn't like Python 3.12
This module prints a bunch of
DeprecationWarning
s: in Python 3.11In Python 3.12,
pkg_resources
is no longer installed automatically in virtualenvs, and these become an error:You can install it via
setuptools
, but installing this unconditionally will cause issues when you are not in a virtualenv, like our Docker image. I went with skipping it for Python 3.12, and not installing the middleware if the import fails (either not installed, or installed in virtualenv withoutsetuptools
). I opened google/sqlcommenter#275 to track the issue.