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

New DeprecationWarnings and PytestMockWarnings whilst building with Python 3.12 #5175

Closed
dermotbradley opened this issue Apr 14, 2024 · 1 comment · Fixed by #5856
Closed
Assignees
Labels
bug Something isn't working correctly

Comments

@dermotbradley
Copy link
Contributor

Bug report

Alpine Edge has now upgraded its Python from 3.11.8 to 3.12.3. Whilst packaging cloud-init with the new Python version some new (mainly deprecation) warnings appear.

The deprecation warnings mainly relate to datetime.datetime.utcfromtimestamp() and datetime.datetime.utcnow().

However there are also the following warnings:

DeprecationWarning: Testing an element's truth value will raise an exception in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.

and

PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager

Steps to reproduce the problem

Environment details

  • Cloud-init version: git main
  • Operating System Distribution: Alpine Edge
  • Cloud provider, platform or installer type: n/a

cloud-init logs

tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_boot_invalid_distro
tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_container_no_ci_log_line
tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_container_ci_log_line
  /home/builder/package/src/cloud-init-24.2/cloudinit/analyze/__init__.py:131: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    kernel_start_timestamp = datetime.utcfromtimestamp(kernel_start)

tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_boot_invalid_distro
tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_container_no_ci_log_line
tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_container_ci_log_line
  /home/builder/package/src/cloud-init-24.2/cloudinit/analyze/__init__.py:132: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    kernel_end_timestamp = datetime.utcfromtimestamp(kernel_end)

tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_boot_invalid_distro
tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_container_no_ci_log_line
tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_container_ci_log_line
  /home/builder/package/src/cloud-init-24.2/cloudinit/analyze/__init__.py:133: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    ci_sysd_start_timestamp = datetime.utcfromtimestamp(ci_sysd_start)

tests/unittests/analyze/test_boot.py::TestAnalyzeBoot::test_container_ci_log_line
  /home/builder/package/src/cloud-init-24.2/cloudinit/analyze/__init__.py:141: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    ci_start = datetime.utcfromtimestamp(last_init_local["timestamp"])

tests/unittests/cmd/devel/test_logs.py::TestCollectLogs::test_collect_logs_creates_tarfile
  /home/builder/package/src/cloud-init-24.2/tests/unittests/cmd/devel/test_logs.py:65: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    date = datetime.utcnow().date().strftime("%Y-%m-%d")

tests/unittests/cmd/devel/test_logs.py::TestCollectLogs::test_collect_logs_creates_tarfile
tests/unittests/cmd/devel/test_logs.py::TestCollectLogs::test_collect_logs_includes_optional_userdata
  /home/builder/package/src/cloud-init-24.2/cloudinit/cmd/devel/logs.py:221: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    log_dir = datetime.utcnow().date().strftime("cloud-init-logs-%Y-%m-%d")

tests/unittests/cmd/devel/test_logs.py::TestCollectLogs::test_collect_logs_includes_optional_userdata
  /home/builder/package/src/cloud-init-24.2/tests/unittests/cmd/devel/test_logs.py:182: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    date = datetime.utcnow().date().strftime("%Y-%m-%d")

tests/unittests/reporting/test_reporting_hyperv.py: 13 warnings
  /home/builder/package/src/cloud-init-24.2/cloudinit/reporting/handlers.py:376: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    datetime.utcfromtimestamp(event.timestamp).isoformat() + "Z"

tests/unittests/reporting/test_reporting_hyperv.py::TextKvpReporter::test_get_boot_telemetry
  /home/builder/package/src/cloud-init-24.2/cloudinit/sources/helpers/azure.py:122: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    datetime.utcfromtimestamp(kernel_start).isoformat() + "Z",

tests/unittests/reporting/test_reporting_hyperv.py::TextKvpReporter::test_get_boot_telemetry
  /home/builder/package/src/cloud-init-24.2/cloudinit/sources/helpers/azure.py:123: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    datetime.utcfromtimestamp(user_start).isoformat() + "Z",

tests/unittests/reporting/test_reporting_hyperv.py::TextKvpReporter::test_get_boot_telemetry
  /home/builder/package/src/cloud-init-24.2/cloudinit/sources/helpers/azure.py:124: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    datetime.utcfromtimestamp(cloudinit_activation).isoformat() + "Z",

tests/unittests/sources/azure/test_errors.py: 48 warnings
  /home/builder/package/src/cloud-init-24.2/tests/unittests/sources/azure/test_errors.py:23: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    timestamp = datetime.datetime.utcnow()

tests/unittests/sources/azure/test_errors.py: 13 warnings
tests/unittests/sources/azure/test_kvp.py: 2 warnings
tests/unittests/sources/test_azure.py: 107 warnings
tests/unittests/sources/test_azure_helper.py: 11 warnings
  /home/builder/package/src/cloud-init-24.2/cloudinit/sources/azure/errors.py:55: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    self.timestamp = datetime.utcnow()

tests/unittests/sources/azure/test_kvp.py::TestReportSuccessToHost::test_report_success_to_host
  /home/builder/package/src/cloud-init-24.2/tests/unittests/sources/azure/test_kvp.py:14: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    timestamp = datetime.utcnow()

tests/unittests/sources/azure/test_kvp.py: 1 warning
tests/unittests/sources/test_azure.py: 49 warnings
  /home/builder/package/src/cloud-init-24.2/cloudinit/sources/azure/kvp.py:52: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    f"timestamp={datetime.utcnow().isoformat()}",

tests/unittests/sources/test_azure.py: 67 warnings
tests/unittests/sources/test_azure_helper.py: 17 warnings
  /home/builder/package/src/cloud-init-24.2/cloudinit/sources/helpers/azure.py:1011: DeprecationWarning: Testing an element's truth value will raise an exception in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.
    if not root.find("./wa:ProvisioningSection", cls.NAMESPACES):

tests/unittests/sources/test_azure.py: 17 warnings
  /home/builder/package/src/cloud-init-24.2/tests/unittests/sources/test_azure.py:293: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    timestamp = datetime.datetime.utcnow()

tests/unittests/sources/test_gce.py::TestDataSourceGCE::test_has_expired
tests/unittests/sources/test_gce.py::TestDataSourceGCE::test_has_expired
  /home/builder/package/src/cloud-init-24.2/cloudinit/sources/DataSourceGCE.py:237: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    return datetime.datetime.utcnow() > expire_time

tests/unittests/test_cli.py: 13 warnings
  /home/builder/package/src/cloud-init-24.2/tests/unittests/test_cli.py:41: PytestMockWarning: Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager
    with mocker.patch(

tests/unittests/test_log.py::TestCloudInitLogger::test_logger_uses_gmtime
  /home/builder/package/src/cloud-init-24.2/tests/unittests/test_log.py:44: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    utc_before = datetime.datetime.utcnow() - datetime.timedelta(0, 0.5)

tests/unittests/test_log.py::TestCloudInitLogger::test_logger_uses_gmtime
  /home/builder/package/src/cloud-init-24.2/tests/unittests/test_log.py:46: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    utc_after = datetime.datetime.utcnow() + datetime.timedelta(0, 0.5)
@dermotbradley dermotbradley added bug Something isn't working correctly new An issue that still needs triage labels Apr 14, 2024
@TheRealFalcon TheRealFalcon removed the new An issue that still needs triage label Apr 15, 2024
@TheRealFalcon
Copy link
Member

Thanks for the report @dermotbradley . I can confirm that on recent versions of python we see these warnings when running tests.

@blackboxsw blackboxsw added this to the cloud-init-24.4 milestone Sep 6, 2024
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 6, 2024
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 6, 2024
Warning message:
DeprecationWarning: Testing an element's truth value will always return True in future versions

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 6, 2024
Warning:
PytestCollectionWarning: cannot collect test class 'TestUpdatePackageSources' because it has a __init__ constructor

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 6, 2024
Deprecation warning:
DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior.

Refs:

https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter
https://peps.python.org/pep-0706/

canonicalGH-5175
@aciba90 aciba90 self-assigned this Nov 7, 2024
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
DeprecationWarning: Testing an element's truth value will
always return True in future versions

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
Warning:
PytestCollectionWarning: cannot collect test class
'TestUpdatePackageSources' because it has a __init__ constructor

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
Deprecation warning:
DeprecationWarning: Python 3.14 will, by default, filter extracted tar
archives and reject files or modify their metadata. Use the filter
argument to control this behavior.

Refs:

https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter
https://peps.python.org/pep-0706/

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
Deprecated message:
DeprecationWarning: Passing a schema to Validator.iter_errors is deprecated
and will be removed in a future release.
Call validator.evolve(schema=new_schema).iter_errors(...) instead.

Refs:
https://github.com/python-jsonschema/jsonschema/releases/tag/v4.0.0

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
DeprecationWarning: Testing an element's truth value will
always return True in future versions

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
Warning:
PytestCollectionWarning: cannot collect test class
'TestUpdatePackageSources' because it has a __init__ constructor

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
Deprecation warning:
DeprecationWarning: Python 3.14 will, by default, filter extracted tar
archives and reject files or modify their metadata. Use the filter
argument to control this behavior.

Refs:

https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter
https://peps.python.org/pep-0706/

canonicalGH-5175
aciba90 added a commit to aciba90/cloud-init that referenced this issue Nov 7, 2024
…onical#5856)

Deprecated message:
DeprecationWarning: Passing a schema to Validator.iter_errors is deprecated
and will be removed in a future release.
Call validator.evolve(schema=new_schema).iter_errors(...) instead.

Refs:
https://github.com/python-jsonschema/jsonschema/releases/tag/v4.0.0

canonicalGH-5175
aciba90 added a commit that referenced this issue Nov 13, 2024
DeprecationWarning: Testing an element's truth value will
always return True in future versions

GH-5175
aciba90 added a commit that referenced this issue Nov 13, 2024
Warning:
PytestCollectionWarning: cannot collect test class
'TestUpdatePackageSources' because it has a __init__ constructor

GH-5175
aciba90 added a commit that referenced this issue Nov 13, 2024
Deprecation warning:
DeprecationWarning: Python 3.14 will, by default, filter extracted tar
archives and reject files or modify their metadata. Use the filter
argument to control this behavior.

Refs:

https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter
https://peps.python.org/pep-0706/

GH-5175
aciba90 added a commit that referenced this issue Nov 13, 2024
Deprecated message:
DeprecationWarning: Passing a schema to Validator.iter_errors is deprecated
and will be removed in a future release.
Call validator.evolve(schema=new_schema).iter_errors(...) instead.

Refs:
https://github.com/python-jsonschema/jsonschema/releases/tag/v4.0.0

GH-5175
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
DeprecationWarning: Testing an element's truth value will
always return True in future versions

canonicalGH-5175
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
Warning:
PytestCollectionWarning: cannot collect test class
'TestUpdatePackageSources' because it has a __init__ constructor

canonicalGH-5175
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
Deprecation warning:
DeprecationWarning: Python 3.14 will, by default, filter extracted tar
archives and reject files or modify their metadata. Use the filter
argument to control this behavior.

Refs:

https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter
https://peps.python.org/pep-0706/

canonicalGH-5175
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
…onical#5856)

Deprecated message:
DeprecationWarning: Passing a schema to Validator.iter_errors is deprecated
and will be removed in a future release.
Call validator.evolve(schema=new_schema).iter_errors(...) instead.

Refs:
https://github.com/python-jsonschema/jsonschema/releases/tag/v4.0.0

canonicalGH-5175
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
…5856)

canonicalGH-5175

Signed-off-by: Mathieu Marchand <mathieu.marchand@canonical.com>
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
DeprecationWarning: Testing an element's truth value will
always return True in future versions

canonicalGH-5175

Signed-off-by: Mathieu Marchand <mathieu.marchand@canonical.com>
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
Warning:
PytestCollectionWarning: cannot collect test class
'TestUpdatePackageSources' because it has a __init__ constructor

canonicalGH-5175

Signed-off-by: Mathieu Marchand <mathieu.marchand@canonical.com>
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
Deprecation warning:
DeprecationWarning: Python 3.14 will, by default, filter extracted tar
archives and reject files or modify their metadata. Use the filter
argument to control this behavior.

Refs:

https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter
https://peps.python.org/pep-0706/

canonicalGH-5175

Signed-off-by: Mathieu Marchand <mathieu.marchand@canonical.com>
mathmarchand pushed a commit to mathmarchand/cloud-init-onb1204 that referenced this issue Nov 21, 2024
…onical#5856)

Deprecated message:
DeprecationWarning: Passing a schema to Validator.iter_errors is deprecated
and will be removed in a future release.
Call validator.evolve(schema=new_schema).iter_errors(...) instead.

Refs:
https://github.com/python-jsonschema/jsonschema/releases/tag/v4.0.0

canonicalGH-5175

Signed-off-by: Mathieu Marchand <mathieu.marchand@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants