-
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] Emit a deprecation warning when the event_loop fixture is expl…
…icitly requested by a coroutine or an async fixture. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
- Loading branch information
Showing
11 changed files
with
238 additions
and
28 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
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
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,159 @@ | ||
from textwrap import dedent | ||
|
||
from pytest import Pytester | ||
|
||
|
||
def test_emit_warning_when_event_loop_is_explicitly_requested_in_coroutine( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.mark.asyncio | ||
async def test_coroutine_emits_warning(event_loop): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest("--asyncio-mode=strict") | ||
result.assert_outcomes(passed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
['*is asynchronous and explicitly requests the "event_loop" fixture*'] | ||
) | ||
|
||
|
||
def test_emit_warning_when_event_loop_is_explicitly_requested_in_coroutine_method( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
class TestEmitsWarning: | ||
@pytest.mark.asyncio | ||
async def test_coroutine_emits_warning(self, event_loop): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest("--asyncio-mode=strict") | ||
result.assert_outcomes(passed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
['*is asynchronous and explicitly requests the "event_loop" fixture*'] | ||
) | ||
|
||
|
||
def test_emit_warning_when_event_loop_is_explicitly_requested_in_coroutine_staticmethod( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
class TestEmitsWarning: | ||
@staticmethod | ||
@pytest.mark.asyncio | ||
async def test_coroutine_emits_warning(event_loop): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest("--asyncio-mode=strict") | ||
result.assert_outcomes(passed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
['*is asynchronous and explicitly requests the "event_loop" fixture*'] | ||
) | ||
|
||
|
||
def test_emit_warning_when_event_loop_is_explicitly_requested_in_coroutine_fixture( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
import pytest_asyncio | ||
@pytest_asyncio.fixture | ||
async def emits_warning(event_loop): | ||
pass | ||
@pytest.mark.asyncio | ||
async def test_uses_fixture(emits_warning): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest("--asyncio-mode=strict") | ||
result.assert_outcomes(passed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
['*is asynchronous and explicitly requests the "event_loop" fixture*'] | ||
) | ||
|
||
|
||
def test_emit_warning_when_event_loop_is_explicitly_requested_in_async_gen_fixture( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
import pytest_asyncio | ||
@pytest_asyncio.fixture | ||
async def emits_warning(event_loop): | ||
yield | ||
@pytest.mark.asyncio | ||
async def test_uses_fixture(emits_warning): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest("--asyncio-mode=strict") | ||
result.assert_outcomes(passed=1, warnings=1) | ||
result.stdout.fnmatch_lines( | ||
['*is asynchronous and explicitly requests the "event_loop" fixture*'] | ||
) | ||
|
||
|
||
def test_does_not_emit_warning_when_event_loop_is_explicitly_requested_in_sync_function( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
def test_uses_fixture(event_loop): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest("--asyncio-mode=strict") | ||
result.assert_outcomes(passed=1) | ||
|
||
|
||
def test_does_not_emit_warning_when_event_loop_is_explicitly_requested_in_sync_fixture( | ||
pytester: Pytester, | ||
): | ||
pytester.makepyfile( | ||
dedent( | ||
"""\ | ||
import pytest | ||
@pytest.fixture | ||
def any_fixture(event_loop): | ||
pass | ||
def test_uses_fixture(any_fixture): | ||
pass | ||
""" | ||
) | ||
) | ||
result = pytester.runpytest("--asyncio-mode=strict") | ||
result.assert_outcomes(passed=1) |
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
Oops, something went wrong.