Skip to content

Commit d7a2d64

Browse files
tjkusonseifertm
authored andcommitted
Skip ID for single factories
1 parent f7de4d8 commit d7a2d64

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

pytest_asyncio/plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,12 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
766766
metafunc.fixturenames.append(_asyncio_loop_factory.__name__)
767767
default_loop_scope = _get_default_test_loop_scope(metafunc.config)
768768
loop_scope = marker_loop_scope or default_loop_scope
769+
# pytest.HIDDEN_PARAM was added in pytest 8.4
770+
hide_id = len(effective_factories) == 1 and hasattr(pytest, "HIDDEN_PARAM")
769771
metafunc.parametrize(
770772
_asyncio_loop_factory.__name__,
771773
effective_factories.values(),
772-
ids=effective_factories.keys(),
774+
ids=(pytest.HIDDEN_PARAM,) if hide_id else effective_factories.keys(),
773775
indirect=True,
774776
scope=loop_scope,
775777
)

tests/test_loop_factory_parametrization.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@
66
from pytest import Pytester
77

88

9+
@pytest.mark.skipif(
10+
not hasattr(pytest, "HIDDEN_PARAM"),
11+
reason="pytest.HIDDEN_PARAM requires pytest 9.0+",
12+
)
13+
def test_single_factory_does_not_add_suffix_to_test_name(
14+
pytester: Pytester,
15+
) -> None:
16+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
17+
pytester.makeconftest(dedent("""\
18+
import asyncio
19+
20+
def pytest_asyncio_loop_factories(config, item):
21+
return {"asyncio": asyncio.new_event_loop}
22+
"""))
23+
pytester.makepyfile(dedent("""\
24+
import pytest
25+
26+
pytest_plugins = "pytest_asyncio"
27+
28+
@pytest.mark.asyncio
29+
async def test_example():
30+
assert True
31+
"""))
32+
result = pytester.runpytest("--asyncio-mode=strict", "--collect-only", "-q")
33+
result.stdout.fnmatch_lines(
34+
["test_single_factory_does_not_add_suffix_to_test_name.py::test_example"]
35+
)
36+
37+
938
def test_named_hook_factories_apply_to_async_tests(pytester: Pytester) -> None:
1039
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
1140
pytester.makeconftest(dedent("""\

0 commit comments

Comments
 (0)