Skip to content

Commit e5bd4e3

Browse files
bolinocroustibatPierlou
authored andcommitted
chore: upgrade dependencies and fix pytest-asyncio deprecated code (#305)
Upgrade dependencies to their latest versions, including update of `pytext-asyncio` from 0.25.3 to 1.1.0. `pytest-asyncio` >= 1.0 has some breaking changes, including the deprecation of `event_loop`, which makes the testing of async features more easy and less verbose, but need some code adaptation to remove `event_loop`. Detail: - https://pytest-asyncio.readthedocs.io/en/latest/reference/changelog.html - pytest-dev/pytest-asyncio#1106
1 parent 840a120 commit e5bd4e3

File tree

9 files changed

+1473
-1315
lines changed

9 files changed

+1473
-1315
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Handle cases of too long columns labels for postgres [#299](https://github.com/datagouv/hydra/pull/299)
1212
- Fix rare issue in `/status/crawler/` endpoint [#301](https://github.com/datagouv/hydra/pull/301) [#302](https://github.com/datagouv/hydra/pull/302)
1313
- Fix typos, deprecated examples and add emojis in README [#304](https://github.com/datagouv/hydra/pull/304)
14+
- Upgrade dependencies and fix pytest-asyncio deprecated code [#305](https://github.com/datagouv/hydra/pull/305)
1415
- Handle new cases of geo columns from csv-detective [#303](https://github.com/datagouv/hydra/pull/303)
1516

1617
## 2.3.0 (2025-07-15)

poetry.lock

Lines changed: 1403 additions & 1218 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dev = [
3636
"mypy>=1.11.0",
3737
"nest_asyncio>=1.5.5",
3838
"pytest>=8.3.0",
39-
"pytest-asyncio>=0.18.3",
39+
"pytest-asyncio>=1.1.0",
4040
"pytest-cov>=5.0.0",
4141
"pytest-mock>=3.7.0",
4242
"ruff>=0.9.3",

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ def setup():
8282

8383

8484
@pytest_asyncio.fixture(autouse=True)
85-
async def mock_pool(mocker, event_loop):
85+
async def mock_pool(mocker):
8686
"""This avoids having different pools attached to different event loops"""
8787
m = mocker.patch("udata_hydra.context.pool")
88-
pool = await asyncpg.create_pool(dsn=DATABASE_URL, max_size=50, loop=event_loop)
88+
pool = await asyncpg.create_pool(dsn=DATABASE_URL, max_size=50)
8989
m.return_value = pool
9090
yield
9191
await pool.close()
9292

9393

9494
@pytest_asyncio.fixture(autouse=True)
95-
async def patch_enqueue(mocker, event_loop):
95+
async def patch_enqueue(mocker):
9696
"""
9797
Patch our enqueue helper
9898
This bypasses rq totally by executing the function in the same event loop
@@ -104,7 +104,7 @@ def _execute(fn, *args, **kwargs):
104104
kwargs.pop("_exception", None)
105105
result = fn(*args, **kwargs)
106106
if asyncio.iscoroutine(result):
107-
loop = event_loop
107+
loop = asyncio.get_running_loop()
108108
coro_result = loop.run_until_complete(result)
109109
return coro_result
110110
return result

tests/test_api/test_api_checks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ async def test_create_check(
182182
setup_catalog,
183183
client,
184184
rmock,
185-
event_loop,
186185
db,
187186
resource,
188187
analysis_mock,

tests/test_crawl/test_backoff.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
nest_asyncio.apply()
2323

2424

25-
async def test_backoff_nb_req(setup_catalog, event_loop, rmock, mocker, fake_check, produce_mock):
25+
async def test_backoff_nb_req(setup_catalog, rmock, mocker, fake_check, produce_mock):
2626
await fake_check(resource=2, resource_id="c5187912-24a5-49ea-a725-5e1e3d472efe")
2727
mocker.patch("udata_hydra.config.BACKOFF_NB_REQ", 1)
2828
mocker.patch("udata_hydra.config.BACKOFF_PERIOD", 0.25)
2929
rurl = RESOURCE_URL
3030
rmock.head(rurl, status=200)
31-
event_loop.run_until_complete(start_checks(iterations=1))
31+
await start_checks(iterations=1)
3232
# verify that we actually backed-off
3333
assert ("HEAD", URL(rurl)) not in rmock.requests
3434

@@ -44,9 +44,7 @@ async def test_backoff_nb_req(setup_catalog, event_loop, rmock, mocker, fake_che
4444
(0, -1, False),
4545
],
4646
)
47-
async def test_backoff_rate_limiting(
48-
setup_catalog, event_loop, rmock, fake_check, produce_mock, ratelimit
49-
):
47+
async def test_backoff_rate_limiting(setup_catalog, rmock, fake_check, produce_mock, ratelimit):
5048
remain, limit, should_backoff = ratelimit
5149
await fake_check(
5250
resource=2,
@@ -59,7 +57,7 @@ async def test_backoff_rate_limiting(
5957
rurl = RESOURCE_URL
6058
rmock.head(rurl, status=200)
6159
rmock.get(rurl, status=200)
62-
event_loop.run_until_complete(start_checks(iterations=1))
60+
await start_checks(iterations=1)
6361
# verify that we actually backed-off
6462
if should_backoff:
6563
assert ("HEAD", URL(rurl)) not in rmock.requests
@@ -68,7 +66,7 @@ async def test_backoff_rate_limiting(
6866

6967

7068
async def test_backoff_rate_limiting_lifted(
71-
setup_catalog, event_loop, rmock, mocker, fake_check, produce_mock, db
69+
setup_catalog, rmock, mocker, fake_check, produce_mock, db
7270
):
7371
await fake_check(
7472
resource=2,
@@ -97,7 +95,7 @@ async def test_backoff_rate_limiting_lifted(
9795

9896

9997
async def test_backoff_rate_limiting_cooled_off(
100-
setup_catalog, event_loop, rmock, mocker, fake_check, produce_mock, db
98+
setup_catalog, rmock, mocker, fake_check, produce_mock, db
10199
):
102100
await fake_check(
103101
resource=2,
@@ -133,9 +131,7 @@ async def test_backoff_rate_limiting_cooled_off(
133131
assert ("HEAD", URL(rurl)) in rmock.requests
134132

135133

136-
async def test_backoff_nb_req_lifted(
137-
setup_catalog, event_loop, rmock, mocker, fake_check, produce_mock, db
138-
):
134+
async def test_backoff_nb_req_lifted(setup_catalog, rmock, mocker, fake_check, produce_mock, db):
139135
await fake_check(resource=2, resource_id="c5187912-24a5-49ea-a725-5e1e3d472efe")
140136
mocker.patch("udata_hydra.config.BACKOFF_NB_REQ", 1)
141137
mocker.patch("udata_hydra.config.BACKOFF_PERIOD", 0.25)
@@ -155,7 +151,7 @@ async def test_backoff_nb_req_lifted(
155151

156152

157153
async def test_backoff_on_429_status_code(
158-
setup_catalog, event_loop, rmock, mocker, fake_check, produce_mock, db
154+
setup_catalog, rmock, mocker, fake_check, produce_mock, db
159155
):
160156
resource_id = "c5187912-24a5-49ea-a725-5e1e3d472efe"
161157
await fake_check(resource=2, resource_id=resource_id)
@@ -186,16 +182,14 @@ async def test_backoff_on_429_status_code(
186182
assert ("HEAD", URL(rurl)) in rmock.requests
187183

188184

189-
async def test_no_backoff_domains(
190-
setup_catalog, event_loop, rmock, mocker, fake_check, produce_mock
191-
):
185+
async def test_no_backoff_domains(setup_catalog, rmock, mocker, fake_check, produce_mock):
192186
await fake_check(resource=2)
193187
mocker.patch("udata_hydra.config.BACKOFF_NB_REQ", 1)
194188
mocker.patch("udata_hydra.config.NO_BACKOFF_DOMAINS", ["example.com"])
195189
magic = MagicMock()
196190
mocker.patch("udata_hydra.context.monitor").return_value = magic
197191
rurl = RESOURCE_URL
198192
rmock.get(rurl, status=200)
199-
event_loop.run_until_complete(start_checks(iterations=1))
193+
await start_checks(iterations=1)
200194
# verify that we actually did not back-off
201195
assert not magic.add_backoff.called

0 commit comments

Comments
 (0)