Skip to content

python: fix quadratic behavior in collection of items using xunit fixtures #7929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2020
Merged
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
11 changes: 11 additions & 0 deletions bench/xunit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
for i in range(5000):
exec(
f"""
class Test{i}:
@classmethod
def setup_class(cls): pass
def test_1(self): pass
def test_2(self): pass
def test_3(self): pass
"""
)
28 changes: 24 additions & 4 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,12 @@ def _inject_setup_module_fixture(self) -> None:
if setup_module is None and teardown_module is None:
return

@fixtures.fixture(autouse=True, scope="module")
@fixtures.fixture(
autouse=True,
scope="module",
# Use a unique name to speed up lookup.
name=f"xunit_setup_module_fixture_{self.obj.__name__}",
)
def xunit_setup_module_fixture(request) -> Generator[None, None, None]:
if setup_module is not None:
_call_with_optional_argument(setup_module, request.module)
Expand All @@ -546,7 +551,12 @@ def _inject_setup_function_fixture(self) -> None:
if setup_function is None and teardown_function is None:
return

@fixtures.fixture(autouse=True, scope="function")
@fixtures.fixture(
autouse=True,
scope="function",
# Use a unique name to speed up lookup.
name=f"xunit_setup_function_fixture_{self.obj.__name__}",
)
def xunit_setup_function_fixture(request) -> Generator[None, None, None]:
if request.instance is not None:
# in this case we are bound to an instance, so we need to let
Expand Down Expand Up @@ -789,7 +799,12 @@ def _inject_setup_class_fixture(self) -> None:
if setup_class is None and teardown_class is None:
return

@fixtures.fixture(autouse=True, scope="class")
@fixtures.fixture(
autouse=True,
scope="class",
# Use a unique name to speed up lookup.
name=f"xunit_setup_class_fixture_{self.obj.__qualname__}",
)
def xunit_setup_class_fixture(cls) -> Generator[None, None, None]:
if setup_class is not None:
func = getimfunc(setup_class)
Expand All @@ -813,7 +828,12 @@ def _inject_setup_method_fixture(self) -> None:
if setup_method is None and teardown_method is None:
return

@fixtures.fixture(autouse=True, scope="function")
@fixtures.fixture(
autouse=True,
scope="function",
# Use a unique name to speed up lookup.
name=f"xunit_setup_method_fixture_{self.obj.__qualname__}",
)
def xunit_setup_method_fixture(self, request) -> Generator[None, None, None]:
method = request.function
if setup_method is not None:
Expand Down