Skip to content

Commit 3d05e99

Browse files
authored
feat!: Remove legacy mode. (#414)
Asyncio modes have been introduced in v0.17.0 which was released on 2022-01-13. In addition to the auto and strict modes, the release defaulted to "legacy" mode for backwards compatibility. The release also issued a deprecation warning when using legacy mode. The default asyncio mode was changed to _strict_ in the v0.19.0 release on 2022-07-13. This change removes legacy mode entirely. Signed-off-by: Michael Seifert <[email protected]>
1 parent 2d8f69d commit 3d05e99

File tree

5 files changed

+4
-163
lines changed

5 files changed

+4
-163
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44

55
UNRELEASED
66
=================
7+
- BREAKING: Removed *legacy* mode. If you're upgrading from v0.19 and you haven't configured ``asyncio_mode = legacy``, you can upgrade without taking any additional action. If you're upgrading from an earlier version or you have explicitly enabled *legacy* mode, you need to switch to *auto* or *strict* mode before upgrading to this version.
78
- Fixed an issue which prevented fixture setup from being cached. `#404 <https://github.com/pytest-dev/pytest-asyncio/pull/404>`_
89

910
0.19.0 (22-07-13)

README.rst

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ This is enough for pytest to pick up pytest-asyncio.
5757
Modes
5858
-----
5959

60-
Starting from ``pytest-asyncio>=0.17``, three modes are provided: *auto*, *strict* and
61-
*legacy*. Starting from ``pytest-asyncio>=0.19`` the *strict* mode is the default.
60+
Pytest-asyncio provides two modes: *auto* and *strict* with *strict* mode being the default.
6261

6362
The mode can be set by ``asyncio_mode`` configuration option in `configuration file
6463
<https://docs.pytest.org/en/latest/reference/customize.html>`_:
@@ -107,18 +106,6 @@ suite.
107106
This mode is used by default for the sake of project inter-compatibility.
108107

109108

110-
Legacy mode
111-
~~~~~~~~~~~
112-
113-
This mode follows rules used by ``pytest-asyncio<0.17``: tests are not auto-marked but
114-
fixtures are.
115-
116-
Deprecation warnings are emitted with suggestion to either switching to ``auto`` mode
117-
or using ``strict`` mode with ``@pytest_asyncio.fixture`` decorators.
118-
119-
The default was changed to ``strict`` in ``pytest-asyncio>=0.19``.
120-
121-
122109
Fixtures
123110
--------
124111

@@ -204,7 +191,7 @@ to redefine the ``event_loop`` fixture to have the same or broader scope.
204191
Async fixtures need the event loop, and so must have the same or narrower scope
205192
than the ``event_loop`` fixture.
206193

207-
*auto* and *legacy* mode automatically converts async fixtures declared with the
194+
*auto* mode automatically converts async fixtures declared with the
208195
standard ``@pytest.fixture`` decorator to *asyncio-driven* versions.
209196

210197

pytest_asyncio/plugin.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import inspect
77
import socket
88
import sys
9-
import warnings
109
from typing import (
1110
Any,
1211
AsyncIterator,
@@ -55,31 +54,13 @@
5554
class Mode(str, enum.Enum):
5655
AUTO = "auto"
5756
STRICT = "strict"
58-
LEGACY = "legacy"
59-
60-
61-
LEGACY_MODE = DeprecationWarning(
62-
"The 'asyncio_mode' default value will change to 'strict' in future, "
63-
"please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' "
64-
"in pytest configuration file."
65-
)
66-
67-
LEGACY_ASYNCIO_FIXTURE = (
68-
"'@pytest.fixture' is applied to {name} "
69-
"in 'legacy' mode, "
70-
"please replace it with '@pytest_asyncio.fixture' as a preparation "
71-
"for switching to 'strict' mode (or use 'auto' mode to seamlessly handle "
72-
"all these fixtures as asyncio-driven)."
73-
)
7457

7558

7659
ASYNCIO_MODE_HELP = """\
7760
'auto' - for automatically handling all async functions by the plugin
7861
'strict' - for autoprocessing disabling (useful if different async frameworks \
7962
should be tested together, e.g. \
8063
both pytest-asyncio and pytest-trio are used in the same project)
81-
'legacy' - for keeping compatibility with pytest-asyncio<0.17: \
82-
auto-handling is disabled but pytest_asyncio.fixture usage is not enforced
8364
"""
8465

8566

@@ -187,8 +168,6 @@ def pytest_configure(config: Config) -> None:
187168
"mark the test as a coroutine, it will be "
188169
"run using an asyncio event loop",
189170
)
190-
if _get_asyncio_mode(config) == Mode.LEGACY:
191-
config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)
192171

193172

194173
@pytest.mark.tryfirst
@@ -217,20 +196,6 @@ def _preprocess_async_fixtures(config: Config, holder: Set[FixtureDef]) -> None:
217196
elif asyncio_mode == Mode.AUTO:
218197
# Enforce asyncio mode if 'auto'
219198
_set_explicit_asyncio_mark(func)
220-
elif asyncio_mode == Mode.LEGACY:
221-
_set_explicit_asyncio_mark(func)
222-
try:
223-
code = func.__code__
224-
except AttributeError:
225-
code = func.__func__.__code__
226-
name = (
227-
f"<fixture {func.__qualname__}, file={code.co_filename}, "
228-
f"line={code.co_firstlineno}>"
229-
)
230-
warnings.warn(
231-
LEGACY_ASYNCIO_FIXTURE.format(name=name),
232-
DeprecationWarning,
233-
)
234199

235200
to_add = []
236201
for name in ("request", "event_loop"):

tests/modes/test_legacy_mode.py

Lines changed: 0 additions & 112 deletions
This file was deleted.

tests/test_asyncio_fixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def test_fixture_with_params(fixture_with_params):
4242
assert fixture_with_params % 2 == 0
4343

4444

45-
@pytest.mark.parametrize("mode", ("auto", "strict", "legacy"))
45+
@pytest.mark.parametrize("mode", ("auto", "strict"))
4646
def test_sync_function_uses_async_fixture(testdir, mode):
4747
testdir.makepyfile(
4848
dedent(

0 commit comments

Comments
 (0)