Skip to content

DeprecationWarning for datetime.utcfromtimestamp() in Python 3.12 #71

@musicinmybrain

Description

@musicinmybrain
python3.12 -m venv _e
. _e/bin/activate
pip install -e .[pydantic]
pip install -r requirements/tests.in
python -m pytest
==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_datetime.py ____________________
_e/lib64/python3.12/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
_e/lib64/python3.12/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
_e/lib64/python3.12/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
_e/lib64/python3.12/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
_e/lib64/python3.12/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
_e/lib64/python3.12/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
_e/lib64/python3.12/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
_e/lib64/python3.12/site-packages/_pytest/pathlib.py:565: in import_path
    importlib.import_module(module_name)
/usr/lib64/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1293: in _gcd_import
    ???
<frozen importlib._bootstrap>:1266: in _find_and_load
    ???
<frozen importlib._bootstrap>:1237: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:841: in _load_unlocked
    ???
_e/lib64/python3.12/site-packages/_pytest/assertion/rewrite.py:178: in exec_module
    exec(co, module.__dict__)
tests/test_datetime.py:5: in <module>
    import pytz
_e/lib64/python3.12/site-packages/pytz/__init__.py:20: in <module>
    from pytz.tzinfo import unpickler, BaseTzInfo
_e/lib64/python3.12/site-packages/pytz/tzinfo.py:27: in <module>
    _epoch = datetime.utcfromtimestamp(0)
E   DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).

This will probably be fixed in pytz at some point; the issue is stub42/pytz#105.

In the longer term, it may be desirable to migrate away from pytz, as summarized in the introductory paragraph of the description for https://pypi.org/project/pytz-deprecation-shim/.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions