File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -175,14 +175,26 @@ def async_warn(nodeid: str) -> None:
175175@hookimpl (trylast = True )
176176def pytest_pyfunc_call (pyfuncitem : "Function" ):
177177 testfunction = pyfuncitem .obj
178- if iscoroutinefunction (testfunction ) or (
179- sys .version_info >= (3 , 6 ) and inspect .isasyncgenfunction (testfunction )
180- ):
178+
179+ try :
180+ # ignoring type as the import is invalid in py37 and mypy thinks its a error
181+ from unittest import IsolatedAsyncioTestCase # type: ignore
182+ except ImportError :
183+ async_ok_in_stdlib = False
184+ else :
185+ async_ok_in_stdlib = isinstance (testfunction .__self__ , IsolatedAsyncioTestCase )
186+
187+ if (
188+ iscoroutinefunction (testfunction )
189+ or (sys .version_info >= (3 , 6 ) and inspect .isasyncgenfunction (testfunction ))
190+ ) and not async_ok_in_stdlib :
181191 async_warn (pyfuncitem .nodeid )
182192 funcargs = pyfuncitem .funcargs
183193 testargs = {arg : funcargs [arg ] for arg in pyfuncitem ._fixtureinfo .argnames }
184194 result = testfunction (** testargs )
185- if hasattr (result , "__await__" ) or hasattr (result , "__aiter__" ):
195+ if (
196+ hasattr (result , "__await__" ) or hasattr (result , "__aiter__" )
197+ ) and not async_ok_in_stdlib :
186198 async_warn (pyfuncitem .nodeid )
187199 return True
188200
Original file line number Diff line number Diff line change 1+ [pytest]
Original file line number Diff line number Diff line change 1+ from unittest import IsolatedAsyncioTestCase # type: ignore
2+
3+
4+ class AsyncArguments (IsolatedAsyncioTestCase ):
5+ async def test_something_async (self ):
6+ async def addition (x , y ):
7+ return x + y
8+
9+ self .assertEqual (await addition (2 , 2 ), 4 )
10+
11+ async def test_something_async_fails (self ):
12+ async def addition (x , y ):
13+ return x + y
14+
15+ self .assertEqual (await addition (2 , 2 ), 3 )
You can’t perform that action at this time.
0 commit comments