Skip to content

Commit cb5f1e0

Browse files
umaannamalaiTimPansinolrafeei
authored
Remove testing for aiohttp versions outside 3 year support window. (#424)
* Remove testing for aiohttp versions outside 3 year support window. * Fix starlette testing Co-authored-by: Uma Annamalai <[email protected]> Co-authored-by: Lalleh Rafeei <[email protected]> * [Mega-Linter] Apply linters fixes * Bump Tests Co-authored-by: Tim Pansino <[email protected]> Co-authored-by: Uma Annamalai <[email protected]> Co-authored-by: Lalleh Rafeei <[email protected]> Co-authored-by: TimPansino <[email protected]>
1 parent 768019d commit cb5f1e0

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

tests/framework_starlette/test_application.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
import pytest
1818
import starlette
19-
20-
from newrelic.common.object_names import callable_name
2119
from testing_support.fixtures import (
2220
override_ignore_status_codes,
2321
validate_transaction_errors,
2422
validate_transaction_metrics,
2523
)
2624

25+
from newrelic.common.object_names import callable_name
26+
2727

2828
@pytest.fixture(scope="session")
2929
def target_application():
@@ -96,27 +96,28 @@ def test_exception_in_middleware(target_application, app_name):
9696
app = target_application[app_name]
9797

9898
from starlette import __version__ as version
99+
99100
starlette_version = tuple(int(v) for v in version.split("."))
100101

101-
# Starlette >=0.15 raises an exception group instead of reraising the ValueError
102+
# Starlette >=0.15 and <0.17 raises an exception group instead of reraising the ValueError
102103
# This only occurs on Python versions >=3.8
103-
if sys.version_info[0:2] > (3, 7) and starlette_version >= (0, 15, 0):
104+
if sys.version_info[0:2] > (3, 7) and starlette_version >= (0, 15, 0) and starlette_version < (0, 17, 0):
104105
from anyio._backends._asyncio import ExceptionGroup
106+
105107
exc_type = ExceptionGroup
106108
else:
107109
exc_type = ValueError
108110

109111
@validate_transaction_metrics(
110112
"_test_application:middleware_factory.<locals>.middleware",
111-
scoped_metrics=[
112-
("Function/_test_application:middleware_factory.<locals>.middleware", 1)
113-
],
113+
scoped_metrics=[("Function/_test_application:middleware_factory.<locals>.middleware", 1)],
114114
rollup_metrics=[FRAMEWORK_METRIC],
115115
)
116116
@validate_transaction_errors(errors=[callable_name(exc_type)])
117117
def _test():
118118
with pytest.raises(exc_type): # Later versions of starlette
119119
app.get("/crash_me_now")
120+
120121
_test()
121122

122123

@@ -161,14 +162,10 @@ def _test():
161162
),
162163
)
163164
@validate_transaction_errors(errors=["builtins:RuntimeError"])
164-
def test_server_error_middleware(
165-
target_application, app_name, transaction_name, path, scoped_metrics
166-
):
165+
def test_server_error_middleware(target_application, app_name, transaction_name, path, scoped_metrics):
167166
@validate_transaction_metrics(
168167
transaction_name,
169-
scoped_metrics=scoped_metrics
170-
+ [("Function/_test_application:runtime_error", 1)]
171-
+ DEFAULT_MIDDLEWARE_METRICS,
168+
scoped_metrics=scoped_metrics + [("Function/_test_application:runtime_error", 1)] + DEFAULT_MIDDLEWARE_METRICS,
172169
rollup_metrics=[FRAMEWORK_METRIC],
173170
)
174171
def _test():
@@ -196,9 +193,7 @@ def _test():
196193
),
197194
),
198195
)
199-
def test_application_handled_error(
200-
target_application, app_name, transaction_name, path, error
201-
):
196+
def test_application_handled_error(target_application, app_name, transaction_name, path, error):
202197
@validate_transaction_errors(errors=[error])
203198
@validate_transaction_metrics(
204199
transaction_name,
@@ -229,9 +224,7 @@ def _test():
229224
),
230225
)
231226
@override_ignore_status_codes(set((500,)))
232-
def test_application_ignored_error(
233-
target_application, app_name, transaction_name, path
234-
):
227+
def test_application_ignored_error(target_application, app_name, transaction_name, path):
235228
@validate_transaction_errors(errors=[])
236229
@validate_transaction_metrics(
237230
transaction_name,
@@ -276,9 +269,7 @@ def _test():
276269

277270
@pytest.mark.parametrize("app_name", ("no_middleware",))
278271
@validate_transaction_errors(errors=["builtins:RuntimeError"])
279-
@validate_transaction_metrics(
280-
"_test_application:CustomRoute", rollup_metrics=[FRAMEWORK_METRIC]
281-
)
272+
@validate_transaction_metrics("_test_application:CustomRoute", rollup_metrics=[FRAMEWORK_METRIC])
282273
def test_starlette_http_exception_after_response_start(target_application, app_name):
283274
app = target_application[app_name]
284275
with pytest.raises(RuntimeError):

tests/framework_starlette/test_graphql.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,32 @@
1313
# limitations under the License.
1414

1515
import json
16+
1617
import pytest
1718
from testing_support.fixtures import dt_enabled, validate_transaction_metrics
1819
from testing_support.validators.validate_span_events import validate_span_events
1920

21+
22+
def get_starlette_version():
23+
import starlette
24+
25+
version = getattr(starlette, "__version__", "0.0.0").split(".")
26+
return tuple(int(x) for x in version)
27+
28+
2029
@pytest.fixture(scope="session")
2130
def target_application():
2231
import _test_graphql
2332

2433
return _test_graphql.target_application
2534

35+
2636
@dt_enabled
2737
@pytest.mark.parametrize("endpoint", ("/async", "/sync"))
38+
@pytest.mark.skipif(get_starlette_version() >= (0, 17), reason="Starlette GraphQL support dropped in v0.17.0")
2839
def test_graphql_metrics_and_attrs(target_application, endpoint):
2940
from graphql import __version__ as version
41+
3042
from newrelic.hooks.framework_graphql import graphene_framework_details
3143

3244
FRAMEWORK_METRICS = [
@@ -65,7 +77,9 @@ def test_graphql_metrics_and_attrs(target_application, endpoint):
6577
rollup_metrics=_test_unscoped_metrics + FRAMEWORK_METRICS,
6678
)
6779
def _test():
68-
response = target_application.make_request("POST", endpoint, body=json.dumps({"query": "{ hello }"}), headers={"Content-Type": "application/json"})
80+
response = target_application.make_request(
81+
"POST", endpoint, body=json.dumps({"query": "{ hello }"}), headers={"Content-Type": "application/json"}
82+
)
6983
assert response.status == 200
7084
assert "Hello!" in response.body.decode("utf-8")
7185

tox.ini

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ envlist =
9595
python-external_requests-{py27,py36,py37,py38,py39,py310,pypy,pypy3},
9696
python-external_urllib3-{py27,py37,pypy}-urllib3{0109},
9797
python-external_urllib3-{py27,py36,py37,py38,py39,py310,pypy,pypy3}-urllib3latest,
98-
python-framework_aiohttp-{py36}-aiohttp{01,0202,02},
99-
python-framework_aiohttp-{py36,py37}-aiohttp0304,
10098
python-framework_aiohttp-{py36,py37,py38,py39,py310,pypy3}-aiohttp03,
10199
python-framework_ariadne-{py36,py37,py38,py39,py310}-ariadnelatest,
102100
python-framework_ariadne-py37-ariadne{0011,0012,0013},
@@ -130,7 +128,8 @@ envlist =
130128
python-framework_pyramid-{pypy3,py36,py37,py38,py39,py310}-Pyramidmaster,
131129
python-framework_sanic-{py38,pypy3}-sanic{190301,1906,1812,1912,200904,210300},
132130
python-framework_sanic-{py36,py37,py38,py310,pypy3}-saniclatest,
133-
python-framework_starlette-{py36,py37,py38,py39,py310, pypy3}-starlette{0014,latest},
131+
python-framework_starlette-{py36,py310,pypy3}-starlette{0014,0015},
132+
python-framework_starlette-{py36,py37,py38,py39,py310, pypy3}-starlette{latest},
134133
python-framework_strawberry-{py37,py38,py39,py310}-strawberrylatest,
135134
libcurl-framework_tornado-{py36,py37,py38,py39,py310,pypy3}-tornado0600,
136135
libcurl-framework_tornado-{py36,py37,py38,py39,py310,pypy3}-tornadomaster,
@@ -223,13 +222,6 @@ deps =
223222
external_requests: requests
224223
external_urllib3-urllib30109: urllib3<1.10
225224
external_urllib3-urllib3latest: urllib3
226-
framework_aiohttp-aiohttp01: multidict<3
227-
framework_aiohttp-aiohttp0202: multidict<3
228-
framework_aiohttp-aiohttp0202: yarl<0.13
229-
framework_aiohttp-aiohttp01: aiohttp<2
230-
framework_aiohttp-aiohttp0202: aiohttp<2.3
231-
framework_aiohttp-aiohttp02: aiohttp<3
232-
framework_aiohttp-aiohttp0304: aiohttp<3.5
233225
framework_aiohttp-aiohttp03: aiohttp<4
234226
framework_ariadne-ariadnelatest: ariadne
235227
framework_ariadne-ariadne0011: ariadne<0.12
@@ -296,6 +288,7 @@ deps =
296288
framework_sanic-sanic{1812,190301,1906}: aiohttp
297289
framework_starlette: graphene
298290
framework_starlette-starlette0014: starlette<0.15
291+
framework_starlette-starlette0015: starlette<0.16
299292
framework_starlette-starlettelatest: starlette
300293
framework_strawberry: starlette
301294
framework_strawberry-strawberrylatest: strawberry-graphql

0 commit comments

Comments
 (0)