MCPcopy
hub / github.com/pydantic/pydantic / test_copy_exclude

Function test_copy_exclude

tests/test_construction.py:179–192  ·  view source on GitHub ↗
(ModelTwo)

Source from the content-addressed store, hash-verified

177
178@pytest.mark.thread_unsafe(reason='`pytest.warns()` is thread unsafe')
179def test_copy_exclude(ModelTwo):
180 m = ModelTwo(a=24, d=Model(a='12'))
181 m2 = deprecated_copy(m, exclude={'b'})
182
183 assert m.a == m2.a == 24
184 assert isinstance(m2.d, Model)
185 assert m2.d.a == 12
186
187 assert hasattr(m2, 'c')
188 assert not hasattr(m2, 'b')
189 assert set(m.model_dump().keys()) == {'a', 'b', 'c', 'd'}
190 assert set(m2.model_dump().keys()) == {'a', 'c', 'd'}
191
192 assert m != m2
193
194
195@pytest.mark.thread_unsafe(reason='`pytest.warns()` is thread unsafe')

Callers

nothing calls this directly

Calls 5

deprecated_copyFunction · 0.85
keysMethod · 0.80
ModelTwoClass · 0.70
ModelClass · 0.70
model_dumpMethod · 0.45

Tested by

no test coverage detected