Skip to content

Commit 8e70b18

Browse files
pgstac: move asyncio-mode config into pytest.ini and remove unnecessary pytest.mark.asyncio tags (#390)
* pgstac: move asyncio-mode config into pytest.ini and remove unnecessary pytest.mark.asyncio tags * Pin pytest-asyncio version in pgstac Co-authored-by: Nathan Zimmerman <[email protected]>
1 parent 93c4b1a commit 8e70b18

File tree

10 files changed

+6
-101
lines changed

10 files changed

+6
-101
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test-sqlalchemy: run-joplin-sqlalchemy
4444

4545
.PHONY: test-pgstac
4646
test-pgstac:
47-
$(run_pgstac) /bin/bash -c 'export && ./scripts/wait-for-it.sh database:5432 && cd /app/stac_fastapi/pgstac/tests/ && pytest -vvv --asyncio-mode=auto'
47+
$(run_pgstac) /bin/bash -c 'export && ./scripts/wait-for-it.sh database:5432 && cd /app/stac_fastapi/pgstac/tests/ && pytest -vvv'
4848

4949
.PHONY: run-database
5050
run-database:

stac_fastapi/pgstac/pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
testpaths = tests
3+
addopts = -sv
4+
asyncio_mode = auto

stac_fastapi/pgstac/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dev": [
2424
"pytest",
2525
"pytest-cov",
26-
"pytest-asyncio",
26+
"pytest-asyncio>=0.17",
2727
"pre-commit",
2828
"requests",
2929
"pypgstac==0.4.5",

stac_fastapi/pgstac/tests/api/test_api.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from datetime import datetime, timedelta
22

3-
import pytest
4-
53
STAC_CORE_ROUTES = [
64
"GET /",
75
"GET /collections",
@@ -23,20 +21,17 @@
2321
]
2422

2523

26-
@pytest.mark.asyncio
2724
async def test_post_search_content_type(app_client):
2825
params = {"limit": 1}
2926
resp = await app_client.post("search", json=params)
3027
assert resp.headers["content-type"] == "application/geo+json"
3128

3229

33-
@pytest.mark.asyncio
3430
async def test_get_search_content_type(app_client):
3531
resp = await app_client.get("search")
3632
assert resp.headers["content-type"] == "application/geo+json"
3733

3834

39-
@pytest.mark.asyncio
4035
async def test_api_headers(app_client):
4136
resp = await app_client.get("/api")
4237
assert (
@@ -45,7 +40,6 @@ async def test_api_headers(app_client):
4540
assert resp.status_code == 200
4641

4742

48-
@pytest.mark.asyncio
4943
async def test_core_router(api_client):
5044
core_routes = set(STAC_CORE_ROUTES)
5145
api_routes = set(
@@ -54,7 +48,6 @@ async def test_core_router(api_client):
5448
assert not core_routes - api_routes
5549

5650

57-
@pytest.mark.asyncio
5851
async def test_transactions_router(api_client):
5952
transaction_routes = set(STAC_TRANSACTION_ROUTES)
6053
api_routes = set(
@@ -63,7 +56,6 @@ async def test_transactions_router(api_client):
6356
assert not transaction_routes - api_routes
6457

6558

66-
@pytest.mark.asyncio
6759
async def test_app_transaction_extension(
6860
app_client, load_test_data, load_test_collection
6961
):
@@ -73,7 +65,6 @@ async def test_app_transaction_extension(
7365
assert resp.status_code == 200
7466

7567

76-
@pytest.mark.asyncio
7768
async def test_app_query_extension(load_test_data, app_client, load_test_collection):
7869
coll = load_test_collection
7970
item = load_test_data("test_item.json")
@@ -87,7 +78,6 @@ async def test_app_query_extension(load_test_data, app_client, load_test_collect
8778
assert len(resp_json["features"]) == 1
8879

8980

90-
@pytest.mark.asyncio
9181
async def test_app_query_extension_limit_1(
9282
load_test_data, app_client, load_test_collection
9383
):
@@ -103,14 +93,12 @@ async def test_app_query_extension_limit_1(
10393
assert len(resp_json["features"]) == 1
10494

10595

106-
@pytest.mark.asyncio
10796
async def test_app_query_extension_limit_eq0(app_client):
10897
params = {"limit": 0}
10998
resp = await app_client.post("/search", json=params)
11099
assert resp.status_code == 400
111100

112101

113-
@pytest.mark.asyncio
114102
async def test_app_query_extension_limit_lt0(
115103
load_test_data, app_client, load_test_collection
116104
):
@@ -124,7 +112,6 @@ async def test_app_query_extension_limit_lt0(
124112
assert resp.status_code == 400
125113

126114

127-
@pytest.mark.asyncio
128115
async def test_app_query_extension_limit_gt10000(
129116
load_test_data, app_client, load_test_collection
130117
):
@@ -138,7 +125,6 @@ async def test_app_query_extension_limit_gt10000(
138125
assert resp.status_code == 400
139126

140127

141-
@pytest.mark.asyncio
142128
async def test_app_query_extension_gt(load_test_data, app_client, load_test_collection):
143129
coll = load_test_collection
144130
item = load_test_data("test_item.json")
@@ -152,7 +138,6 @@ async def test_app_query_extension_gt(load_test_data, app_client, load_test_coll
152138
assert len(resp_json["features"]) == 0
153139

154140

155-
@pytest.mark.asyncio
156141
async def test_app_query_extension_gte(
157142
load_test_data, app_client, load_test_collection
158143
):
@@ -168,7 +153,6 @@ async def test_app_query_extension_gte(
168153
assert len(resp_json["features"]) == 1
169154

170155

171-
@pytest.mark.asyncio
172156
async def test_app_sort_extension(load_test_data, app_client, load_test_collection):
173157
coll = load_test_collection
174158
first_item = load_test_data("test_item.json")
@@ -209,7 +193,6 @@ async def test_app_sort_extension(load_test_data, app_client, load_test_collecti
209193
assert resp_json["features"][0]["id"] == second_item["id"]
210194

211195

212-
@pytest.mark.asyncio
213196
async def test_search_invalid_date(load_test_data, app_client, load_test_collection):
214197
coll = load_test_collection
215198
first_item = load_test_data("test_item.json")
@@ -225,7 +208,6 @@ async def test_search_invalid_date(load_test_data, app_client, load_test_collect
225208
assert resp.status_code == 400
226209

227210

228-
@pytest.mark.asyncio
229211
async def test_bbox_3d(load_test_data, app_client, load_test_collection):
230212
coll = load_test_collection
231213
first_item = load_test_data("test_item.json")
@@ -244,7 +226,6 @@ async def test_bbox_3d(load_test_data, app_client, load_test_collection):
244226
assert len(resp_json["features"]) == 1
245227

246228

247-
@pytest.mark.asyncio
248229
async def test_app_search_response(load_test_data, app_client, load_test_collection):
249230
coll = load_test_collection
250231
params = {
@@ -260,7 +241,6 @@ async def test_app_search_response(load_test_data, app_client, load_test_collect
260241
assert resp_json.get("stac_extensions") is None
261242

262243

263-
@pytest.mark.asyncio
264244
async def test_search_point_intersects(
265245
load_test_data, app_client, load_test_collection
266246
):
@@ -282,7 +262,6 @@ async def test_search_point_intersects(
282262
assert len(resp_json["features"]) == 1
283263

284264

285-
@pytest.mark.asyncio
286265
async def test_search_line_string_intersects(
287266
load_test_data, app_client, load_test_collection
288267
):

stac_fastapi/pgstac/tests/clients/test_postgres.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import uuid
22
from typing import Callable
33

4-
import pytest
54
from stac_pydantic import Collection, Item
65

76
# from tests.conftest import MockStarletteRequest
87

98

10-
@pytest.mark.asyncio
119
async def test_create_collection(app_client, load_test_data: Callable):
1210
in_json = load_test_data("test_collection.json")
1311
in_coll = Collection.parse_obj(in_json)
@@ -24,7 +22,6 @@ async def test_create_collection(app_client, load_test_data: Callable):
2422
assert post_coll.dict(exclude={"links"}) == get_coll.dict(exclude={"links"})
2523

2624

27-
@pytest.mark.asyncio
2825
async def test_update_collection(app_client, load_test_collection):
2926
in_coll = load_test_collection
3027
in_coll.keywords.append("newkeyword")
@@ -40,7 +37,6 @@ async def test_update_collection(app_client, load_test_collection):
4037
assert "newkeyword" in get_coll.keywords
4138

4239

43-
@pytest.mark.asyncio
4440
async def test_delete_collection(app_client, load_test_collection):
4541
in_coll = load_test_collection
4642

@@ -51,7 +47,6 @@ async def test_delete_collection(app_client, load_test_collection):
5147
assert resp.status_code == 404
5248

5349

54-
@pytest.mark.asyncio
5550
async def test_create_item(app_client, load_test_data: Callable, load_test_collection):
5651
coll = load_test_collection
5752

@@ -73,7 +68,6 @@ async def test_create_item(app_client, load_test_data: Callable, load_test_colle
7368
assert in_item.dict(exclude={"links"}) == get_item.dict(exclude={"links"})
7469

7570

76-
@pytest.mark.asyncio
7771
async def test_update_item(app_client, load_test_collection, load_test_item):
7872
coll = load_test_collection
7973
item = load_test_item
@@ -91,7 +85,6 @@ async def test_update_item(app_client, load_test_collection, load_test_item):
9185
assert get_item.properties.description == "Update Test"
9286

9387

94-
@pytest.mark.asyncio
9588
async def test_delete_item(app_client, load_test_collection, load_test_item):
9689
coll = load_test_collection
9790
item = load_test_item
@@ -103,7 +96,6 @@ async def test_delete_item(app_client, load_test_collection, load_test_item):
10396
assert resp.status_code == 404
10497

10598

106-
@pytest.mark.asyncio
10799
async def test_get_collection_items(app_client, load_test_collection, load_test_item):
108100
coll = load_test_collection
109101
item = load_test_item

stac_fastapi/pgstac/tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def api_client(pg):
118118
return api
119119

120120

121-
@pytest.mark.asyncio
122121
@pytest.fixture(scope="session")
123122
async def app(api_client):
124123
time.time()
@@ -130,7 +129,6 @@ async def app(api_client):
130129
await close_db_connection(app)
131130

132131

133-
@pytest.mark.asyncio
134132
@pytest.fixture(scope="session")
135133
async def app_client(app):
136134
async with AsyncClient(app=app, base_url="http://test") as c:

stac_fastapi/pgstac/tests/resources/test_collection.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from typing import Callable
22

33
import pystac
4-
import pytest
54
from stac_pydantic import Collection
65

76

8-
@pytest.mark.asyncio
97
async def test_create_collection(app_client, load_test_data: Callable):
108
in_json = load_test_data("test_collection.json")
119
in_coll = Collection.parse_obj(in_json)
@@ -22,7 +20,6 @@ async def test_create_collection(app_client, load_test_data: Callable):
2220
assert post_coll.dict(exclude={"links"}) == get_coll.dict(exclude={"links"})
2321

2422

25-
@pytest.mark.asyncio
2623
async def test_update_collection(app_client, load_test_data, load_test_collection):
2724
in_coll = load_test_collection
2825
in_coll.keywords.append("newkeyword")
@@ -38,7 +35,6 @@ async def test_update_collection(app_client, load_test_data, load_test_collectio
3835
assert "newkeyword" in get_coll.keywords
3936

4037

41-
@pytest.mark.asyncio
4238
async def test_delete_collection(
4339
app_client, load_test_data: Callable, load_test_collection
4440
):
@@ -51,7 +47,6 @@ async def test_delete_collection(
5147
assert resp.status_code == 404
5248

5349

54-
@pytest.mark.asyncio
5550
async def test_create_collection_conflict(app_client, load_test_data: Callable):
5651
in_json = load_test_data("test_collection.json")
5752
Collection.parse_obj(in_json)
@@ -68,15 +63,13 @@ async def test_create_collection_conflict(app_client, load_test_data: Callable):
6863
assert resp.status_code == 409
6964

7065

71-
@pytest.mark.asyncio
7266
async def test_delete_missing_collection(
7367
app_client,
7468
):
7569
resp = await app_client.delete("/collections")
7670
assert resp.status_code == 405
7771

7872

79-
@pytest.mark.asyncio
8073
async def test_update_new_collection(app_client, load_test_collection):
8174
in_coll = load_test_collection
8275
in_coll.id = "test-updatenew"
@@ -85,15 +78,13 @@ async def test_update_new_collection(app_client, load_test_collection):
8578
assert resp.status_code == 404
8679

8780

88-
@pytest.mark.asyncio
8981
async def test_nocollections(
9082
app_client,
9183
):
9284
resp = await app_client.get("/collections")
9385
assert resp.status_code == 200
9486

9587

96-
@pytest.mark.asyncio
9788
async def test_returns_valid_collection(app_client, load_test_data):
9889
"""Test updating a collection which already exists"""
9990
in_json = load_test_data("test_collection.json")
@@ -117,7 +108,6 @@ async def test_returns_valid_collection(app_client, load_test_data):
117108
collection.validate()
118109

119110

120-
@pytest.mark.asyncio
121111
async def test_returns_valid_links_in_collections(app_client, load_test_data):
122112
"""Test links from listing collections"""
123113
in_json = load_test_data("test_collection.json")
@@ -166,7 +156,6 @@ async def test_returns_valid_links_in_collections(app_client, load_test_data):
166156
] == []
167157

168158

169-
@pytest.mark.asyncio
170159
async def test_returns_license_link(app_client, load_test_collection):
171160
coll = load_test_collection
172161

stac_fastapi/pgstac/tests/resources/test_conformance.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def test_landing_page_health(response):
4444
]
4545

4646

47-
@pytest.mark.asyncio
4847
@pytest.mark.parametrize("rel_type,expected_media_type,expected_path", link_tests)
4948
async def test_landing_page_links(
5049
response_json: Dict, app_client, rel_type, expected_media_type, expected_path

0 commit comments

Comments
 (0)