Skip to content

Commit 7f802bb

Browse files
committed
[feat] Deprecates the optional scope keyword argument of asyncio markers. Users are encouraged to use the loop_scope keyword argument. The loop_scope kwarg does exactly the same, though its naming is consistent with the loop_scope kwarg of pytest_asyncio.fixture.
Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
1 parent 1bb4299 commit 7f802bb

22 files changed

+96
-68
lines changed

docs/source/concepts_module_scope_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
loop: asyncio.AbstractEventLoop
66

77

8-
@pytest.mark.asyncio(scope="module")
8+
@pytest.mark.asyncio(loop_scope="module")
99
async def test_remember_loop():
1010
global loop
1111
loop = asyncio.get_running_loop()
1212

1313

14-
@pytest.mark.asyncio(scope="module")
14+
@pytest.mark.asyncio(loop_scope="module")
1515
async def test_runs_in_a_loop():
1616
global loop
1717
assert asyncio.get_running_loop() is loop

docs/source/how-to-guides/class_scoped_loop_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55

6-
@pytest.mark.asyncio(scope="class")
6+
@pytest.mark.asyncio(loop_scope="class")
77
class TestInOneEventLoopPerClass:
88
loop: asyncio.AbstractEventLoop
99

docs/source/how-to-guides/module_scoped_loop_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
pytestmark = pytest.mark.asyncio(scope="module")
5+
pytestmark = pytest.mark.asyncio(loop_scope="module")
66

77
loop: asyncio.AbstractEventLoop
88

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import pytest
22

3-
pytestmark = pytest.mark.asyncio(scope="package")
3+
pytestmark = pytest.mark.asyncio(loop_scope="package")

docs/source/how-to-guides/run_class_tests_in_same_loop.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
======================================================
22
How to run all tests in a class in the same event loop
33
======================================================
4-
All tests can be run inside the same event loop by marking them with ``pytest.mark.asyncio(scope="class")``.
4+
All tests can be run inside the same event loop by marking them with ``pytest.mark.asyncio(loop_scope="class")``.
55
This is easily achieved by using the *asyncio* marker as a class decorator.
66

77
.. include:: class_scoped_loop_example.py

docs/source/how-to-guides/run_module_tests_in_same_loop.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=======================================================
22
How to run all tests in a module in the same event loop
33
=======================================================
4-
All tests can be run inside the same event loop by marking them with ``pytest.mark.asyncio(scope="module")``.
4+
All tests can be run inside the same event loop by marking them with ``pytest.mark.asyncio(loop_scope="module")``.
55
This is easily achieved by adding a `pytestmark` statement to your module.
66

77
.. include:: module_scoped_loop_example.py

docs/source/how-to-guides/run_package_tests_in_same_loop.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
========================================================
22
How to run all tests in a package in the same event loop
33
========================================================
4-
All tests can be run inside the same event loop by marking them with ``pytest.mark.asyncio(scope="package")``.
4+
All tests can be run inside the same event loop by marking them with ``pytest.mark.asyncio(loop_scope="package")``.
55
Add the following code to the ``__init__.py`` of the test package:
66

77
.. include:: package_scoped_loop_example.py

docs/source/how-to-guides/run_session_tests_in_same_loop.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
==========================================================
22
How to run all tests in the session in the same event loop
33
==========================================================
4-
All tests can be run inside the same event loop by marking them with ``pytest.mark.asyncio(scope="session")``.
4+
All tests can be run inside the same event loop by marking them with ``pytest.mark.asyncio(loop_scope="session")``.
55
The easiest way to mark all tests is via a ``pytest_collection_modifyitems`` hook in the ``conftest.py`` at the root folder of your test suite.
66

77
.. include:: session_scoped_loop_example.py

docs/source/how-to-guides/session_scoped_loop_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
def pytest_collection_modifyitems(items):
77
pytest_asyncio_tests = (item for item in items if is_async_test(item))
8-
session_scope_marker = pytest.mark.asyncio(scope="session")
8+
session_scope_marker = pytest.mark.asyncio(loop_scope="session")
99
for async_test in pytest_asyncio_tests:
1010
async_test.add_marker(session_scope_marker, append=False)

docs/source/reference/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog
33
=========
44

5+
0.24.0 (UNRELEASED)
6+
===================
7+
- Deprecates the optional `scope` keyword argument of asyncio markers. Users are encouraged to use the `loop_scope` keyword argument. The `loop_scope` kwarg does exactly the same, though its naming is consistent with the `loop_scope` kwarg of ``pytest_asyncio.fixture``.
8+
59
0.23.8 (UNRELEASED)
610
===================
711
- Fixes a bug that caused duplicate markers in async tests `#813 <https://github.com/pytest-dev/pytest-asyncio/issues/813>`_

0 commit comments

Comments
 (0)