-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Test items based on asynchronous generators always exit with *…
…xfail* status and emit a warning during the collection phase. This behavior is consistent with synchronous yield tests. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
- Loading branch information
Showing
4 changed files
with
250 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
from textwrap import dedent | ||
|
||
from pytest import Pytester | ||
|
||
|
||
def test_asyncio_mark_on_sync_function_emits_warning(pytester: Pytester): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.mark.asyncio | ||
def test_a(): | ||
pass | ||
""" | ||
) | ||
) | ||
pytester.makefile( | ||
".ini", | ||
pytest=dedent( | ||
"""\ | ||
[pytest] | ||
asyncio_mode = strict | ||
filterwarnings = | ||
default | ||
""" | ||
), | ||
) | ||
result = pytester.runpytest() | ||
result.assert_outcomes(passed=1) | ||
result.stdout.fnmatch_lines( | ||
["*is marked with '@pytest.mark.asyncio' but it is not an async function.*"] | ||
) | ||
|
||
|
||
def test_asyncio_mark_on_async_generator_function_emits_warning_in_strict_mode( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.mark.asyncio | ||
async def test_a(): | ||
yield | ||
""" | ||
) | ||
) | ||
pytester.makefile( | ||
".ini", | ||
pytest=dedent( | ||
"""\ | ||
[pytest] | ||
asyncio_mode = strict | ||
filterwarnings = | ||
default | ||
""" | ||
), | ||
) | ||
result = pytester.runpytest() | ||
result.assert_outcomes(xfailed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
["*Tests based on asynchronous generators are not supported*"] | ||
) | ||
|
||
|
||
def test_asyncio_mark_on_async_generator_function_emits_warning_in_auto_mode( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
async def test_a(): | ||
yield | ||
""" | ||
) | ||
) | ||
pytester.makefile( | ||
".ini", | ||
pytest=dedent( | ||
"""\ | ||
[pytest] | ||
asyncio_mode = auto | ||
filterwarnings = | ||
default | ||
""" | ||
), | ||
) | ||
result = pytester.runpytest() | ||
result.assert_outcomes(xfailed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
["*Tests based on asynchronous generators are not supported*"] | ||
) | ||
|
||
|
||
def test_asyncio_mark_on_async_generator_method_emits_warning_in_strict_mode( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
class TestAsyncGenerator: | ||
@pytest.mark.asyncio | ||
async def test_a(self): | ||
yield | ||
""" | ||
) | ||
) | ||
pytester.makefile( | ||
".ini", | ||
pytest=dedent( | ||
"""\ | ||
[pytest] | ||
asyncio_mode = strict | ||
filterwarnings = | ||
default | ||
""" | ||
), | ||
) | ||
result = pytester.runpytest() | ||
result.assert_outcomes(xfailed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
["*Tests based on asynchronous generators are not supported*"] | ||
) | ||
|
||
|
||
def test_asyncio_mark_on_async_generator_method_emits_warning_in_auto_mode( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
class TestAsyncGenerator: | ||
@staticmethod | ||
async def test_a(): | ||
yield | ||
""" | ||
) | ||
) | ||
pytester.makefile( | ||
".ini", | ||
pytest=dedent( | ||
"""\ | ||
[pytest] | ||
asyncio_mode = auto | ||
filterwarnings = | ||
default | ||
""" | ||
), | ||
) | ||
result = pytester.runpytest() | ||
result.assert_outcomes(xfailed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
["*Tests based on asynchronous generators are not supported*"] | ||
) | ||
|
||
|
||
def test_asyncio_mark_on_async_generator_staticmethod_emits_warning_in_strict_mode( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
class TestAsyncGenerator: | ||
@staticmethod | ||
@pytest.mark.asyncio | ||
async def test_a(): | ||
yield | ||
""" | ||
) | ||
) | ||
pytester.makefile( | ||
".ini", | ||
pytest=dedent( | ||
"""\ | ||
[pytest] | ||
asyncio_mode = strict | ||
filterwarnings = | ||
default | ||
""" | ||
), | ||
) | ||
result = pytester.runpytest() | ||
result.assert_outcomes(xfailed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
["*Tests based on asynchronous generators are not supported*"] | ||
) | ||
|
||
|
||
def test_asyncio_mark_on_async_generator_staticmethod_emits_warning_in_auto_mode( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
class TestAsyncGenerator: | ||
@staticmethod | ||
async def test_a(): | ||
yield | ||
""" | ||
) | ||
) | ||
pytester.makefile( | ||
".ini", | ||
pytest=dedent( | ||
"""\ | ||
[pytest] | ||
asyncio_mode = auto | ||
filterwarnings = | ||
default | ||
""" | ||
), | ||
) | ||
result = pytester.runpytest() | ||
result.assert_outcomes(xfailed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
["*Tests based on asynchronous generators are not supported*"] | ||
) |
This file was deleted.
Oops, something went wrong.