MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_class_from_parent

Function test_class_from_parent

testing/test_collection.py:1388–1401  ·  view source on GitHub ↗

Ensure Class.from_parent can forward custom arguments to the constructor.

(pytester: Pytester, request: FixtureRequest)

Source from the content-addressed store, hash-verified

1386
1387
1388def test_class_from_parent(pytester: Pytester, request: FixtureRequest) -> None:
1389 """Ensure Class.from_parent can forward custom arguments to the constructor."""
1390
1391 class MyCollector(pytest.Class):
1392 def __init__(self, name, parent, x):
1393 super().__init__(name, parent)
1394 self.x = x
1395
1396 @classmethod
1397 def from_parent(cls, parent, *, name, x):
1398 return super().from_parent(parent=parent, name=name, x=x)
1399
1400 collector = MyCollector.from_parent(parent=request.session, name="foo", x=10)
1401 assert collector.x == 10
1402
1403
1404class TestImportModeImportlib:

Callers

nothing calls this directly

Calls 1

from_parentMethod · 0.45

Tested by

no test coverage detected