1717import  pytest 
1818import  starlette 
1919from  testing_support .fixtures  import  override_ignore_status_codes 
20+ from  testing_support .validators .validate_code_level_metrics  import  (
21+     validate_code_level_metrics ,
22+ )
23+ from  testing_support .validators .validate_transaction_errors  import  (
24+     validate_transaction_errors ,
25+ )
26+ from  testing_support .validators .validate_transaction_metrics  import  (
27+     validate_transaction_metrics ,
28+ )
2029
2130from  newrelic .common .object_names  import  callable_name 
22- from  testing_support . validators . validate_code_level_metrics  import  validate_code_level_metrics 
23- from   testing_support . validators . validate_transaction_errors   import   validate_transaction_errors 
24- from   testing_support . validators . validate_transaction_metrics   import   validate_transaction_metrics 
31+ from  newrelic . common . package_version_utils  import  get_package_version_tuple 
32+ 
33+ starlette_version   =   get_package_version_tuple ( "starlette" )[: 3 ] 
2534
26- starlette_version  =  tuple (int (x ) for  x  in  starlette .__version__ .split ("." ))
2735
2836@pytest .fixture (scope = "session" ) 
2937def  target_application ():
@@ -78,6 +86,7 @@ def test_application_non_async(target_application, app_name):
7886    response  =  app .get ("/non_async" )
7987    assert  response .status  ==  200 
8088
89+ 
8190# Starting in Starlette v0.20.1, the ExceptionMiddleware class 
8291# has been moved to the starlette.middleware.exceptions from 
8392# starlette.exceptions 
@@ -96,8 +105,10 @@ def test_application_non_async(target_application, app_name):
96105    ),
97106)
98107
108+ 
99109@pytest .mark .parametrize ( 
100-     "app_name, transaction_name" , middleware_test , 
110+     "app_name, transaction_name" , 
111+     middleware_test , 
101112) 
102113def  test_application_nonexistent_route (target_application , app_name , transaction_name ):
103114    @validate_transaction_metrics ( 
@@ -117,10 +128,6 @@ def _test():
117128def  test_exception_in_middleware (target_application , app_name ):
118129    app  =  target_application [app_name ]
119130
120-     from  starlette  import  __version__  as  version 
121- 
122-     starlette_version  =  tuple (int (v ) for  v  in  version .split ("." ))
123- 
124131    # Starlette >=0.15 and <0.17 raises an exception group instead of reraising the ValueError 
125132    # This only occurs on Python versions >=3.8 
126133    if  sys .version_info [0 :2 ] >  (3 , 7 ) and  starlette_version  >=  (0 , 15 , 0 ) and  starlette_version  <  (0 , 17 , 0 ):
@@ -272,9 +279,8 @@ def _test():
272279    ),
273280)
274281
275- @pytest .mark .parametrize ( 
276-     "app_name,scoped_metrics" , middleware_test_exception  
277- ) 
282+ 
283+ @pytest .mark .parametrize ("app_name,scoped_metrics" , middleware_test_exception ) 
278284def  test_starlette_http_exception (target_application , app_name , scoped_metrics ):
279285    @validate_transaction_errors (errors = ["starlette.exceptions:HTTPException" ]) 
280286    @validate_transaction_metrics ( 
0 commit comments