1313pytestmark = [pytest .mark .anyio , pytest .mark .async_client , pytest .mark .constructors ]
1414
1515check_all_methods = pytest .mark .parametrize (
16- "method_name, pass_args" ,
16+ [ "method_name" , " pass_args"] ,
1717 [
1818 ("comment_check" , True ),
1919 ("key_sites" , False ),
3737@pytest .mark .parametrize (
3838 "status_code" ,
3939 [
40- pytest .param (code , marks = pytest .mark .akismet_fixed_response (status_code = code ))
40+ pytest .param (
41+ code .value , marks = pytest .mark .akismet_fixed_response (status_code = code )
42+ )
4143 for code in HTTPStatus
4244 if 400 <= code < 600
4345 ],
44- ids = [code for code in HTTPStatus if 400 <= code < 600 ],
46+ ids = [code . value for code in HTTPStatus if 400 <= code < 600 ],
4547)
4648async def test_error_status (
4749 akismet_async_client_fixed_response : akismet .AsyncClient ,
4850 akismet_common_kwargs : dict ,
49- status_code : HTTPStatus ,
51+ status_code : int ,
5052 method_name : str ,
5153 pass_args : bool ,
5254):
@@ -55,15 +57,13 @@ async def test_error_status(
5557 code indicating an error.
5658
5759 """
60+ method = getattr (akismet_async_client_fixed_response , method_name )
61+ args = akismet_common_kwargs if pass_args else {}
5862 with pytest .raises (
5963 akismet .RequestError ,
60- match = f"Akismet responded with error status: { status_code . value } " ,
64+ match = f"Akismet responded with error status: { status_code } " ,
6165 ):
62- method = getattr (akismet_async_client_fixed_response , method_name )
63- if pass_args :
64- await method (** akismet_common_kwargs )
65- else :
66- await method ()
66+ await method (** args )
6767
6868
6969@check_all_methods
@@ -78,12 +78,10 @@ async def test_error_timeout(
7878 RequestError is raised when the request to Akismet times out.
7979
8080 """
81+ method = getattr (akismet_async_client_exception , method_name )
82+ args = akismet_common_kwargs if pass_args else {}
8183 with pytest .raises (akismet .RequestError , match = "Akismet timed out." ):
82- method = getattr (akismet_async_client_exception , method_name )
83- if pass_args :
84- await method (** akismet_common_kwargs )
85- else :
86- await method ()
84+ await method (** args )
8785
8886
8987@check_all_methods
@@ -98,12 +96,10 @@ async def test_error_other_httpx(
9896 RequestError is raised when a generic httpx request error occurs.
9997
10098 """
99+ method = getattr (akismet_async_client_exception , method_name )
100+ args = akismet_common_kwargs if pass_args else {}
101101 with pytest .raises (akismet .RequestError , match = "Error making request to Akismet." ):
102- method = getattr (akismet_async_client_exception , method_name )
103- if pass_args :
104- await method (** akismet_common_kwargs )
105- else :
106- await method ()
102+ await method (** args )
107103
108104
109105@check_all_methods
@@ -119,12 +115,10 @@ async def test_error_other(
119115 request.
120116
121117 """
118+ method = getattr (akismet_async_client_exception , method_name )
119+ args = akismet_common_kwargs if pass_args else {}
122120 with pytest .raises (akismet .RequestError , match = "Error making request to Akismet." ):
123- method = getattr (akismet_async_client_exception , method_name )
124- if pass_args :
125- await method (** akismet_common_kwargs )
126- else :
127- await method ()
121+ await method (** args )
128122
129123
130124@pytest .mark .parametrize ("method_name" , ["comment_check" , "submit_ham" , "submit_spam" ])
@@ -145,7 +139,7 @@ async def test_unknown_argument(
145139
146140
147141@pytest .mark .parametrize (
148- "method_name, pass_args" ,
142+ [ "method_name" , " pass_args"] ,
149143 [
150144 ("comment_check" , True ),
151145 ("submit_ham" , True ),
@@ -166,9 +160,7 @@ async def test_protocol_error(
166160 response.
167161
168162 """
163+ method = getattr (akismet_async_client_fixed_response , method_name )
164+ args = akismet_common_kwargs if pass_args else {}
169165 with pytest .raises (akismet .ProtocolError ):
170- method = getattr (akismet_async_client_fixed_response , method_name )
171- if pass_args :
172- await method (** akismet_common_kwargs )
173- else :
174- await method ()
166+ await method (** args )
0 commit comments