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/1142.fixed.rst

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this fragment more precise (a user could mistakenly interpret this as thinking we haven't been emitting this warning at all) and remove the implementation detail about Config.issue_config_time_warning?

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The deprecation warning for an unset `asyncio_default_fixture_loop_scope` is now visible to pytest: it appears in the warnings summary and can be filtered with `-W` and `filterwarnings`.
4 changes: 3 additions & 1 deletion pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ def pytest_configure(config: Config) -> None:
default_fixture_loop_scope = config.getini("asyncio_default_fixture_loop_scope")
_validate_scope(default_fixture_loop_scope, "asyncio_default_fixture_loop_scope")
if not default_fixture_loop_scope:
warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
config.issue_config_time_warning(
PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET), stacklevel=2
)

default_test_loop_scope = config.getini("asyncio_default_test_loop_scope")
_validate_scope(default_test_loop_scope, "asyncio_default_test_loop_scope")
Expand Down
48 changes: 48 additions & 0 deletions tests/test_fixture_loop_scopes.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify these changes? Some of the assertions pass on main and, as-written, obfuscates the behaviour we're trying to protect. I'd also expect a test that covers suppressing this warning through -W and filterwarnings.

Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,54 @@ async def test_runs_in_fixture_loop(fixture_loop):
result.assert_outcomes(passed=1)


_UNSET_FIXTURE_LOOP_SCOPE_WARNING = (
"*PytestDeprecationWarning: The configuration option "
'"asyncio_default_fixture_loop_scope" is unset.*'
)


def test_unset_default_fixture_loop_scope_warning_appears_in_summary(
pytester: Pytester,
):
"""
The warning is emitted during configure, so it must still be recorded.

https://github.com/pytest-dev/pytest-asyncio/issues/1142
"""
pytester.makepyfile("async def test_it(): pass")
result = pytester.runpytest("--asyncio-mode=auto")
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
["*warnings summary*", _UNSET_FIXTURE_LOOP_SCOPE_WARNING]
)


@pytest.mark.parametrize(
("ini", "args"),
(
pytest.param(
"", ("-Wignore::pytest.PytestDeprecationWarning",), id="command-line-W"
),
pytest.param(
"filterwarnings = ignore::pytest.PytestDeprecationWarning",
(),
id="filterwarnings-ini",
),
),
)
def test_unset_default_fixture_loop_scope_warning_is_filterable(
pytester: Pytester,
ini: str,
args: tuple[str, ...],
):
"""Being recorded properly also means users can silence it."""
pytester.makeini(f"[pytest]\n{ini}")
pytester.makepyfile("async def test_it(): pass")
result = pytester.runpytest("--asyncio-mode=auto", *args)
result.assert_outcomes(passed=1, warnings=0)
result.stdout.no_fnmatch_line(_UNSET_FIXTURE_LOOP_SCOPE_WARNING)


def test_invalid_default_fixture_loop_scope_raises_error(pytester: Pytester):
pytester.makeini("""\
[pytest]
Expand Down
Loading