unittest: fix quadratic behavior in collection of unittests using setUpClass/setup_method

This is similar to 50114d4731876dae; I missed that unittest does the
same thing.
This commit is contained in:
Ran Benita 2020-11-01 15:09:32 +02:00
parent a95da7a425
commit 489f6f4499
2 changed files with 19 additions and 1 deletions

13
bench/unit_test.py Normal file
View File

@ -0,0 +1,13 @@
from unittest import TestCase # noqa: F401
for i in range(15000):
exec(
f"""
class Test{i}(TestCase):
@classmethod
def setUpClass(cls): pass
def test_1(self): pass
def test_2(self): pass
def test_3(self): pass
"""
)

View File

@ -119,7 +119,12 @@ def _make_xunit_fixture(
if setup is None and teardown is None:
return None
@pytest.fixture(scope=scope, autouse=True)
@pytest.fixture(
scope=scope,
autouse=True,
# Use a unique name to speed up lookup.
name=f"unittest_{setup_name}_fixture_{obj.__qualname__}",
)
def fixture(self, request: FixtureRequest) -> Generator[None, None, None]:
if _is_skipped(self):
reason = self.__unittest_skip_why__