Ensure Class.from_parent can forward custom arguments to the constructor.
(pytester: Pytester, request: FixtureRequest)
| 1386 | |
| 1387 | |
| 1388 | def 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 | |
| 1404 | class TestImportModeImportlib: |
nothing calls this directly
no test coverage detected