oceanprotocol / pdr-backend

Instructions & code to run predictoors, traders, more.
Apache License 2.0
22 stars 15 forks source link

[Warning] DeprecationWarning: datetime.datetime.utcnow() ... scheduled for removal #1258

Closed trentmc closed 3 days ago

trentmc commented 1 week ago

Summary

In console, run:

pytest pdr_backend/predictoor/test

Tests will pass, but it will give the warning:

pdr_backend/predictoor/test/test_predictoor_agent.py: 30 warnings
  /Users/trentmc/code/pdr-backend/pdr_backend/util/time_types.py:133: 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).
    dt = datetime.utcnow()

Full traceback

====================================================================================================================================== 1 passed in 1.06s ======================================================================================================================================
(venv) trentmc@trents-m3: ~/code/pdr-backend $ pytest pdr_backend/predictoor/test
===================================================================================================================================== test session starts =====================================================================================================================================
platform darwin -- Python 3.12.3, pytest-8.2.2, pluggy-1.5.0
rootdir: /Users/trentmc/code/pdr-backend
configfile: pytest.ini
plugins: web3-6.19.0, typeguard-4.2.1, env-1.1.3, dash-2.17.1, asyncio-0.21.1, requests-mock-1.12.1
asyncio: mode=Mode.STRICT
collected 20 items                                                                                                                                                                                                                                                                            

pdr_backend/predictoor/test/test_find_shared_slots.py ......                                                                                                                                                                                                                            [ 30%]
pdr_backend/predictoor/test/test_predictoor_agent.py ...........                                                                                                                                                                                                                        [ 85%]
pdr_backend/predictoor/test/test_stakes_per_slot.py ...                                                                                                                                                                                                                                 [100%]

====================================================================================================================================== warnings summary =======================================================================================================================================
pdr_backend/predictoor/test/test_predictoor_agent.py: 30 warnings
  /Users/trentmc/code/pdr-backend/pdr_backend/util/time_types.py:133: 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).
    dt = datetime.utcnow()

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================================================================== 20 passed, 30 warnings in 12.75s ===============================================================================================================================
calina-c commented 1 week ago

@kdetry I saw this update as part of step 3. Are you ok if I replace datetime.utcnow() with datetime.now(datetime.UTC)? Should I check anything more other than the tests?

calina-c commented 3 days ago

I don't see this anymore and no ignore was added to pytest.ini, specifically for this error. I assume some dependency upgrades covered it. I looked for the responsible PR but could not find it. Either way, I am closing this ticket since now there are no warnings in our test runs.

If needed, I will reopen.