opensafely-core / opensafely-core/opensafely-cli
Fix deprecation warnings
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2
- Forks
- 5
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 4
Description
When testing with Python 3.12, there are several warnings. These are a mixture of:
- the use of
pkg_resources; see also #233 - our tests using
datetime.utcnow()instead ofdatetime.datetime.now(datetime.UTC) - warnings in vendored packages that probably will disappear when they are upgraded
=============================== warnings summary ===============================
tests/conftest.py:10
/home/runner/work/opensafely-cli/opensafely-cli/tests/conftest.py:10: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
opensafely/_vendor/certifi/core.py:36
/home/runner/work/opensafely-cli/opensafely-cli/opensafely/_vendor/certifi/core.py:36: DeprecationWarning: path is deprecated. Use files() instead. Refer to https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy for migration advice.
_CACERT_CTX = get_path("opensafely._vendor.certifi", "cacert.pem")
opensafely/_vendor/google/protobuf/internal/well_known_types.py:91
/home/runner/work/opensafely-cli/opensafely-cli/opensafely/_vendor/google/protobuf/internal/well_known_types.py:91: 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).
_EPOCH_DATETIME_NAIVE = datetime.datetime.utcfromtimestamp(0)
tests/test_codelists.py::test_codelists_update
tests/test_codelists.py::test_codelists_update
/home/runner/work/opensafely-cli/opensafely-cli/opensafely/codelists.py:89: 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).
"downloaded_at": f"{datetime.datetime.utcnow()}Z",
tests/test_init.py::test_should_version_check
tests/test_init.py::test_should_version_check
/home/runner/work/opensafely-cli/opensafely-cli/opensafely/__init__.py:45: 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).
four_hours_ago = datetime.utcnow() - timedelta(hours=4)
tests/test_init.py::test_should_version_check
/home/runner/work/opensafely-cli/opensafely-cli/tests/test_init.py:15: 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() - timedelta(hours=5)).timestamp()
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================== 233 passed, 8 warnings in 63.59s (0:01:03) ==================
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by rerunning the tests with Python 3.12 and inspect the warnings in tests/conftest.py, opensafely/codelists.py, opensafely/init.py, and tests/test_init.py. Check #233 for the pkg_resources work and distinguish project warnings from those in opensafely/_vendor. Done means the actionable project warnings are addressed and the test suite passes without them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, testing-qa
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 54/100