Skip to content

Commit 2bf4cf5

Browse files
committed
relax pin on httpx and respx, switch to anyio from pytest-asyncio, fix all warnings
To fix the 3.10 warnings we relax the pins on httpx and respx and tried to relax the pin on pytest-asyncio but ultimately moved to anyio. We switch to anyio from pytest-asyncio because the latest version of pytest-asyncio kept throwing errors and anyio is already a dependency of httpx. Warnings popped up due to not using a context manager for open(), typically in json.load(open(filename)), so these were changed. Warnings also popped up due to non-async cli tests using pytest.mark.anyio, so these were removed.
1 parent 8535d4b commit 2bf4cf5

File tree

13 files changed

+145
-144
lines changed

13 files changed

+145
-144
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
install_requires = [
2727
'click>=8.0.0',
2828
'geojson',
29-
'httpx==0.23.0',
29+
'httpx>=0.23.0',
3030
'jsonschema',
3131
'pyjwt>=2.1',
3232
'tqdm>=4.56',
3333
'typing-extensions',
3434
]
3535

36-
test_requires = ['pytest', 'pytest-asyncio==0.16', 'pytest-cov', 'respx==0.19']
36+
test_requires = ['pytest', 'anyio', 'pytest-cov', 'respx>=0.20']
3737

3838
lint_requires = ['flake8', 'mypy', 'yapf']
3939

tests/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def get_test_file_json():
5050

5151
def func(filename):
5252
file_path = _test_data_path / filename
53-
return json.load(open(file_path, 'r'))
53+
with open(file_path, 'r') as f:
54+
res = json.load(f)
55+
return res
5456

5557
return func
5658

@@ -147,3 +149,8 @@ def multipolygon_geom_geojson():
147149
[37.791595458984375, 14.945448293647944],
148150
[37.791595458984375, 14.84923123791421]]]]
149151
} # yapf: disable
152+
153+
154+
@pytest.fixture
155+
def anyio_backend():
156+
return 'asyncio'

tests/integration/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_disable_limiter(monkeypatch):
2828

2929

3030
@pytest.fixture
31-
@pytest.mark.asyncio
31+
@pytest.mark.anyio
3232
async def session():
3333
async with planet.Session() as ps:
3434
yield ps

tests/integration/test_data_api.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def search_response(item_descriptions):
7171

7272

7373
@respx.mock
74-
@pytest.mark.asyncio
74+
@pytest.mark.anyio
7575
async def test_search_basic(item_descriptions, search_response, session):
7676

7777
quick_search_url = f'{TEST_URL}/quick-search'
@@ -105,7 +105,7 @@ async def test_search_basic(item_descriptions, search_response, session):
105105

106106

107107
@respx.mock
108-
@pytest.mark.asyncio
108+
@pytest.mark.anyio
109109
async def test_search_name(item_descriptions, search_response, session):
110110

111111
quick_search_url = f'{TEST_URL}/quick-search'
@@ -141,7 +141,7 @@ async def test_search_name(item_descriptions, search_response, session):
141141

142142

143143
@respx.mock
144-
@pytest.mark.asyncio
144+
@pytest.mark.anyio
145145
async def test_search_filter(item_descriptions,
146146
search_filter,
147147
search_response,
@@ -178,7 +178,7 @@ async def test_search_filter(item_descriptions,
178178

179179

180180
@respx.mock
181-
@pytest.mark.asyncio
181+
@pytest.mark.anyio
182182
async def test_search_sort(item_descriptions,
183183
search_filter,
184184
search_response,
@@ -201,7 +201,7 @@ async def test_search_sort(item_descriptions,
201201

202202

203203
@respx.mock
204-
@pytest.mark.asyncio
204+
@pytest.mark.anyio
205205
async def test_search_limit(item_descriptions,
206206
search_filter,
207207
search_response,
@@ -226,7 +226,7 @@ async def test_search_limit(item_descriptions,
226226

227227

228228
@respx.mock
229-
@pytest.mark.asyncio
229+
@pytest.mark.anyio
230230
async def test_create_search_basic(search_filter, session):
231231

232232
page_response = {
@@ -262,7 +262,7 @@ async def test_create_search_basic(search_filter, session):
262262

263263

264264
@respx.mock
265-
@pytest.mark.asyncio
265+
@pytest.mark.anyio
266266
async def test_create_search_email(search_filter, session):
267267

268268
page_response = {
@@ -300,7 +300,7 @@ async def test_create_search_email(search_filter, session):
300300

301301

302302
@respx.mock
303-
@pytest.mark.asyncio
303+
@pytest.mark.anyio
304304
async def test_get_search_success(search_id, search_result, session):
305305
get_url = f'{TEST_SEARCHES_URL}/{search_id}'
306306
mock_resp = httpx.Response(HTTPStatus.OK, json=search_result)
@@ -311,7 +311,7 @@ async def test_get_search_success(search_id, search_result, session):
311311

312312

313313
@respx.mock
314-
@pytest.mark.asyncio
314+
@pytest.mark.anyio
315315
async def test_get_search_id_doesnt_exist(search_id, session):
316316
get_url = f'{TEST_SEARCHES_URL}/{search_id}'
317317

@@ -328,7 +328,7 @@ async def test_get_search_id_doesnt_exist(search_id, session):
328328

329329

330330
@respx.mock
331-
@pytest.mark.asyncio
331+
@pytest.mark.anyio
332332
async def test_update_search_basic(search_filter, session):
333333

334334
page_response = {
@@ -367,7 +367,7 @@ async def test_update_search_basic(search_filter, session):
367367

368368

369369
@respx.mock
370-
@pytest.mark.asyncio
370+
@pytest.mark.anyio
371371
@pytest.mark.parametrize("limit, expected_list_length", [(None, 4), (3, 3)])
372372
async def test_list_searches_success(limit,
373373
expected_list_length,
@@ -386,7 +386,7 @@ async def test_list_searches_success(limit,
386386

387387

388388
@respx.mock
389-
@pytest.mark.asyncio
389+
@pytest.mark.anyio
390390
@pytest.mark.parametrize("sort, rel_url",
391391
[(LIST_SORT_DEFAULT, ''),
392392
('created asc', '?_sort=created+asc')])
@@ -402,7 +402,7 @@ async def test_list_searches_sort(sort, rel_url, search_result, session):
402402

403403

404404
@respx.mock
405-
@pytest.mark.asyncio
405+
@pytest.mark.anyio
406406
@pytest.mark.parametrize("search_type, rel_url",
407407
[(LIST_SEARCH_TYPE_DEFAULT, ''),
408408
('saved', '?search_type=saved')])
@@ -421,7 +421,7 @@ async def test_list_searches_searchtype(search_type,
421421

422422

423423
@respx.mock
424-
@pytest.mark.asyncio
424+
@pytest.mark.anyio
425425
@pytest.mark.parametrize(
426426
"sort, search_type, expectation",
427427
[('DOESNOTEXIST', 'ANY', pytest.raises(exceptions.ClientError)),
@@ -442,7 +442,7 @@ async def test_list_searches_args_do_not_match(sort,
442442

443443

444444
@respx.mock
445-
@pytest.mark.asyncio
445+
@pytest.mark.anyio
446446
@pytest.mark.parametrize("retcode, expectation",
447447
[(204, does_not_raise()),
448448
(404, pytest.raises(exceptions.APIError))])
@@ -459,7 +459,7 @@ async def test_delete_search(retcode, expectation, session):
459459

460460

461461
@respx.mock
462-
@pytest.mark.asyncio
462+
@pytest.mark.anyio
463463
@pytest.mark.parametrize("search_id, valid", [(VALID_SEARCH_ID, True),
464464
('invalid', False)])
465465
@pytest.mark.parametrize("limit, expected_count", [(None, 3), (2, 2)])
@@ -500,7 +500,7 @@ async def test_run_search_basic(item_descriptions,
500500

501501

502502
@respx.mock
503-
@pytest.mark.asyncio
503+
@pytest.mark.anyio
504504
@pytest.mark.parametrize("sort, rel_url, valid",
505505
[(SEARCH_SORT_DEFAULT, '', True),
506506
('acquired asc', '?_sort=acquired+asc', True),
@@ -537,7 +537,7 @@ async def test_run_search_sort(item_descriptions,
537537

538538

539539
@respx.mock
540-
@pytest.mark.asyncio
540+
@pytest.mark.anyio
541541
async def test_run_search_doesnotexist(session):
542542
route = respx.get(f'{TEST_SEARCHES_URL}/{VALID_SEARCH_ID}/results')
543543
route.return_value = httpx.Response(404)
@@ -550,7 +550,7 @@ async def test_run_search_doesnotexist(session):
550550

551551

552552
@respx.mock
553-
@pytest.mark.asyncio
553+
@pytest.mark.anyio
554554
async def test_get_stats_success(search_filter, session):
555555

556556
page_response = {
@@ -584,7 +584,7 @@ async def test_get_stats_success(search_filter, session):
584584

585585

586586
@respx.mock
587-
@pytest.mark.asyncio
587+
@pytest.mark.anyio
588588
async def test_get_stats_invalid_interval(search_filter, session):
589589
cl = DataClient(session, base_url=TEST_URL)
590590

@@ -593,7 +593,7 @@ async def test_get_stats_invalid_interval(search_filter, session):
593593

594594

595595
@respx.mock
596-
@pytest.mark.asyncio
596+
@pytest.mark.anyio
597597
async def test_list_item_assets_success(session):
598598
item_type_id = 'PSScene'
599599
item_id = '20221003_002705_38_2461'
@@ -637,7 +637,7 @@ async def test_list_item_assets_success(session):
637637

638638

639639
@respx.mock
640-
@pytest.mark.asyncio
640+
@pytest.mark.anyio
641641
async def test_list_item_assets_missing(session):
642642
item_type_id = 'PSScene'
643643
item_id = '20221003_002705_38_2461xx'
@@ -653,7 +653,7 @@ async def test_list_item_assets_missing(session):
653653

654654

655655
@respx.mock
656-
@pytest.mark.asyncio
656+
@pytest.mark.anyio
657657
@pytest.mark.parametrize("asset_type_id, expectation",
658658
[('basic_udm2', does_not_raise()),
659659
('invalid', pytest.raises(exceptions.ClientError))])
@@ -703,7 +703,7 @@ async def test_get_asset(asset_type_id, expectation, session):
703703

704704

705705
@respx.mock
706-
@pytest.mark.asyncio
706+
@pytest.mark.anyio
707707
@pytest.mark.parametrize("status, expectation", [('inactive', True),
708708
('active', False)])
709709
async def test_activate_asset_success(status, expectation, session):
@@ -732,7 +732,7 @@ async def test_activate_asset_success(status, expectation, session):
732732

733733

734734
@respx.mock
735-
@pytest.mark.asyncio
735+
@pytest.mark.anyio
736736
async def test_activate_asset_invalid_asset(session):
737737
cl = DataClient(session, base_url=TEST_URL)
738738

@@ -741,7 +741,7 @@ async def test_activate_asset_invalid_asset(session):
741741

742742

743743
@respx.mock
744-
@pytest.mark.asyncio
744+
@pytest.mark.anyio
745745
async def test_wait_asset_success(session):
746746
asset_url = f'{TEST_URL}/asset'
747747

@@ -774,7 +774,7 @@ async def test_wait_asset_success(session):
774774

775775

776776
@respx.mock
777-
@pytest.mark.asyncio
777+
@pytest.mark.anyio
778778
async def test_wait_asset_max_attempts(session):
779779
asset_url = f'{TEST_URL}/asset'
780780

@@ -803,7 +803,7 @@ async def test_wait_asset_max_attempts(session):
803803

804804

805805
@respx.mock
806-
@pytest.mark.asyncio
806+
@pytest.mark.anyio
807807
@pytest.mark.parametrize("exists, overwrite",
808808
[(False, False), (True, False), (True, True),
809809
(False, True)])
@@ -870,7 +870,7 @@ async def _stream_img():
870870

871871

872872
@respx.mock
873-
@pytest.mark.asyncio
873+
@pytest.mark.anyio
874874
@pytest.mark.parametrize("hashes_match, md5_entry, expectation",
875875
[(True, True, does_not_raise()),
876876
(False, True, pytest.raises(exceptions.ClientError)),

0 commit comments

Comments
 (0)