Skip to content

Commit a40333a

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 <[email protected]>
1 parent 85c1517 commit a40333a

24 files changed

+99
-70
lines changed

docs/source/concepts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ You may notice that the individual levels resemble the possible `scopes of a pyt
3232
Pytest-asyncio provides one asyncio event loop for each pytest collector.
3333
By default, each test runs in the event loop provided by the *Function* collector, i.e. tests use the loop with the narrowest scope.
3434
This gives the highest level of isolation between tests.
35-
If two or more tests share a common ancestor collector, the tests can be configured to run in their ancestor's loop by passing the appropriate *scope* keyword argument to the *asyncio* mark.
35+
If two or more tests share a common ancestor collector, the tests can be configured to run in their ancestor's loop by passing the appropriate *loop_scope* keyword argument to the *asyncio* mark.
3636
For example, the following two tests use the asyncio event loop provided by the *Module* collector:
3737

3838
.. include:: concepts_module_scope_example.py

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)

0 commit comments

Comments
 (0)