@@ -126,7 +126,7 @@ async def test_anything(any_fixture):
126126 )
127127
128128
129- def test_strict_mode_marked_test_errors_unmarked_fixture (pytester : Pytester ):
129+ def test_strict_mode_marked_test_unmarked_fixture_warning (pytester : Pytester ):
130130 pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
131131 pytester .makepyfile (
132132 dedent (
@@ -136,19 +136,78 @@ def test_strict_mode_marked_test_errors_unmarked_fixture(pytester: Pytester):
136136 # Not using pytest_asyncio.fixture
137137 @pytest.fixture()
138138 async def any_fixture():
139- raise RuntimeError()
139+ pass
140140
141141 @pytest.mark.asyncio
142142 async def test_anything(any_fixture):
143+ # suppress unawaited coroutine warning
144+ try:
145+ any_fixture.send(None)
146+ except StopIteration:
147+ pass
148+ """
149+ )
150+ )
151+ result = pytester .runpytest_subprocess ("--asyncio-mode=strict" , "-W default" )
152+ result .assert_outcomes (passed = 1 , failed = 0 , skipped = 0 , warnings = 1 )
153+ result .stdout .fnmatch_lines (
154+ [
155+ "*warnings summary*" ,
156+ (
157+ "test_strict_mode_marked_test_unmarked_fixture_warning.py::"
158+ "test_anything"
159+ ),
160+ (
161+ "*/pytest_asyncio/plugin.py:*: PytestDeprecationWarning: "
162+ "asyncio test 'test_anything' requested async "
163+ "@pytest.fixture 'any_fixture' in strict mode. "
164+ "You might want to use @pytest_asyncio.fixture or switch to "
165+ "auto mode. "
166+ "This will become an error in future versions of flake8-asyncio."
167+ ),
168+ ],
169+ )
170+
171+
172+ # autouse is not handled in any special way currently
173+ def test_strict_mode_marked_test_unmarked_autouse_fixture_warning (pytester : Pytester ):
174+ pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
175+ pytester .makepyfile (
176+ dedent (
177+ """\
178+ import pytest
179+
180+ # Not using pytest_asyncio.fixture
181+ @pytest.fixture(autouse=True)
182+ async def any_fixture():
143183 pass
184+
185+ @pytest.mark.asyncio
186+ async def test_anything(any_fixture):
187+ # suppress unawaited coroutine warning
188+ try:
189+ any_fixture.send(None)
190+ except StopIteration:
191+ pass
144192 """
145193 )
146194 )
147195 result = pytester .runpytest_subprocess ("--asyncio-mode=strict" , "-W default" )
148- result .assert_outcomes (failed = 1 , skipped = 0 , warnings = 1 )
196+ result .assert_outcomes (passed = 1 , warnings = 1 )
149197 result .stdout .fnmatch_lines (
150198 [
151- "*asyncio test requested async fixture not marked asyncio, in strict mode*" ,
152- "*coroutine 'any_fixture' was never awaited*" ,
199+ "*warnings summary*" ,
200+ (
201+ "test_strict_mode_marked_test_unmarked_autouse_fixture_warning.py::"
202+ "test_anything"
203+ ),
204+ (
205+ "*/pytest_asyncio/plugin.py:*: PytestDeprecationWarning: "
206+ "*asyncio test 'test_anything' requested async "
207+ "@pytest.fixture 'any_fixture' in strict mode. "
208+ "You might want to use @pytest_asyncio.fixture or switch to "
209+ "auto mode. "
210+ "This will become an error in future versions of flake8-asyncio."
211+ ),
153212 ],
154213 )
0 commit comments