Skip to content

Commit

Permalink
[refactor] Moved test for warning generated when sync functions are m…
Browse files Browse the repository at this point in the history
…arked with "asyncio" into a separate test module.

The "test_simple" module is named too general. Thus, it serves as a magnet for all kinds of tests that aren't connected to each other. This is one step to break up the "test_simple" module into more coherent test modules.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
  • Loading branch information
seifertm committed Oct 24, 2023
1 parent 660893d commit 5a474bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
33 changes: 33 additions & 0 deletions tests/test_asyncio_mark_on_sync_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from textwrap import dedent


def test_warn_asyncio_marker_for_regular_func(testdir):
testdir.makepyfile(
dedent(
"""\
import pytest
pytest_plugins = 'pytest_asyncio'
@pytest.mark.asyncio
def test_a():
pass
"""
)
)
testdir.makefile(
".ini",
pytest=dedent(
"""\
[pytest]
asyncio_mode = strict
filterwarnings =
default
"""
),
)
result = testdir.runpytest()
result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines(
["*is marked with '@pytest.mark.asyncio' but it is not an async function.*"]
)
32 changes: 0 additions & 32 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,38 +300,6 @@ async def test_no_warning_on_skip():
result.assert_outcomes(skipped=1)


def test_warn_asyncio_marker_for_regular_func(testdir):
testdir.makepyfile(
dedent(
"""\
import pytest
pytest_plugins = 'pytest_asyncio'
@pytest.mark.asyncio
def test_a():
pass
"""
)
)
testdir.makefile(
".ini",
pytest=dedent(
"""\
[pytest]
asyncio_mode = strict
filterwarnings =
default
"""
),
)
result = testdir.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_invalid_asyncio_mode(testdir):
result = testdir.runpytest("-o", "asyncio_mode=True")
result.stderr.no_fnmatch_line("INTERNALERROR> *")
Expand Down

0 comments on commit 5a474bd

Please sign in to comment.