MCPcopy
hub / github.com/pytest-dev/pytest / test_class_from_parent

Function test_class_from_parent

testing/test_collection.py:1611–1624  ·  view source on GitHub ↗

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

(request: FixtureRequest)

Source from the content-addressed store, hash-verified

1609
1610
1611def test_class_from_parent(request: FixtureRequest) -> None:
1612 """Ensure Class.from_parent can forward custom arguments to the constructor."""
1613
1614 class MyCollector(pytest.Class):
1615 def __init__(self, name, parent, x):
1616 super().__init__(name, parent)
1617 self.x = x
1618
1619 @classmethod
1620 def from_parent(cls, parent, *, name, x): # type: ignore[override]
1621 return super().from_parent(parent=parent, name=name, x=x)
1622
1623 collector = MyCollector.from_parent(parent=request.session, name="foo", x=10)
1624 assert collector.x == 10
1625
1626
1627class TestImportModeImportlib:

Callers

nothing calls this directly

Calls 1

from_parentMethod · 0.45

Tested by

no test coverage detected