Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1584.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an invalid ``loop_scope`` in the ``asyncio`` marker being reported as a bare ``AssertionError`` exposing a Python set repr, instead of a usage error that names the argument and lists the valid scopes.
3 changes: 1 addition & 2 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,7 @@ def _parse_asyncio_marker(
scope = asyncio_marker.kwargs.get("loop_scope") or asyncio_marker.kwargs.get(
"scope"
)
if scope is not None:
assert scope in {"function", "class", "module", "package", "session"}
_validate_scope(scope, "loop_scope")
marker_value = asyncio_marker.kwargs.get("loop_factories")
if marker_value is None:
return scope, None
Expand Down
20 changes: 20 additions & 0 deletions tests/test_fixture_loop_scopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,23 @@ def test_invalid_default_fixture_loop_scope_raises_error(pytester: Pytester):
"function, class, module, package, session."
]
)


def test_invalid_marker_loop_scope_raises_error(pytester: Pytester):
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
pytester.makepyfile("""\
import pytest

@pytest.mark.asyncio(loop_scope="invalid_scope")
async def test_invalid_loop_scope():
pass
""")
result = pytester.runpytest("--assert=plain")
# The exception class is rendered as pytest.UsageError on newer pytest and as
# _pytest.config.exceptions.UsageError on the oldest supported version.
result.stdout.fnmatch_lines(
[
"*UsageError: 'invalid_scope' is not a valid loop_scope. "
"Valid scopes are: function, class, module, package, session."
]
)
Loading