@@ -1050,6 +1050,7 @@ def __post_init__(self):
10501050 create_autospec (WithPostInit ()),
10511051 ]:
10521052 with self .subTest (mock = mock ):
1053+ self .assertIsInstance (mock , WithPostInit )
10531054 self .assertIsInstance (mock .a , int )
10541055 self .assertIsInstance (mock .b , int )
10551056
@@ -1072,6 +1073,7 @@ class WithDefault:
10721073 create_autospec (WithDefault (1 )),
10731074 ]:
10741075 with self .subTest (mock = mock ):
1076+ self .assertIsInstance (mock , WithDefault )
10751077 self .assertIsInstance (mock .a , int )
10761078 self .assertIsInstance (mock .b , int )
10771079
@@ -1087,6 +1089,7 @@ def b(self) -> int:
10871089 create_autospec (WithMethod (1 )),
10881090 ]:
10891091 with self .subTest (mock = mock ):
1092+ self .assertIsInstance (mock , WithMethod )
10901093 self .assertIsInstance (mock .a , int )
10911094 mock .b .assert_not_called ()
10921095
@@ -1102,11 +1105,29 @@ class WithNonFields:
11021105 create_autospec (WithNonFields (1 )),
11031106 ]:
11041107 with self .subTest (mock = mock ):
1108+ self .assertIsInstance (mock , WithNonFields )
11051109 with self .assertRaisesRegex (AttributeError , msg ):
11061110 mock .a
11071111 with self .assertRaisesRegex (AttributeError , msg ):
11081112 mock .b
11091113
1114+ def test_dataclass_special_attrs (self ):
1115+ @dataclass
1116+ class Description :
1117+ name : str
1118+
1119+ for mock in [
1120+ create_autospec (Description , instance = True ),
1121+ create_autospec (Description (1 )),
1122+ ]:
1123+ with self .subTest (mock = mock ):
1124+ self .assertIsInstance (mock , Description )
1125+ self .assertIs (mock .__class__ , Description )
1126+ self .assertIsInstance (mock .__dataclass_fields__ , MagicMock )
1127+ self .assertIsInstance (mock .__dataclass_params__ , MagicMock )
1128+ self .assertIsInstance (mock .__match_args__ , MagicMock )
1129+ self .assertIsInstance (mock .__hash__ , MagicMock )
1130+
11101131class TestCallList (unittest .TestCase ):
11111132
11121133 def test_args_list_contains_call_list (self ):
0 commit comments