MCPcopy Index your code
hub / github.com/python/cpython / test_missing_default_factory

Method test_missing_default_factory

Lib/test/test_dataclasses/__init__.py:965–985  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

963 self.assertNotIn('x', D.__dict__)
964
965 def test_missing_default_factory(self):
966 # Test that MISSING works the same as a default factory not
967 # being specified (which is really the same as a default not
968 # being specified, too).
969 @dataclass
970 class C:
971 x: int=field(default_factory=MISSING)
972 with self.assertRaisesRegex(TypeError,
973 r'__init__\(\) missing 1 required '
974 'positional argument'):
975 C()
976 self.assertNotIn('x', C.__dict__)
977
978 @dataclass
979 class D:
980 x: int=field(default=MISSING, default_factory=MISSING)
981 with self.assertRaisesRegex(TypeError,
982 r'__init__\(\) missing 1 required '
983 'positional argument'):
984 D()
985 self.assertNotIn('x', D.__dict__)
986
987 def test_missing_repr(self):
988 self.assertIn('MISSING_TYPE object', repr(MISSING))

Callers

nothing calls this directly

Calls 4

assertRaisesRegexMethod · 0.95
assertNotInMethod · 0.95
CClass · 0.70
DClass · 0.70

Tested by

no test coverage detected