MCPcopy
hub / github.com/pydantic/pydantic / test_positional_only

Function test_positional_only

tests/test_deprecated_validate_arguments.py:149–167  ·  view source on GitHub ↗
(create_module)

Source from the content-addressed store, hash-verified

147
148
149def test_positional_only(create_module):
150 with pytest.warns(PydanticDeprecatedSince20):
151 module = create_module(
152 # language=Python
153 """
154from pydantic.deprecated.decorator import validate_arguments
155
156@validate_arguments
157def foo(a, b, /, c=None):
158 return f'{a}, {b}, {c}'
159"""
160 )
161 assert module.foo(1, 2) == '1, 2, None'
162 assert module.foo(1, 2, 44) == '1, 2, 44'
163 assert module.foo(1, 2, c=44) == '1, 2, 44'
164 with pytest.raises(TypeError, match="positional-only argument passed as keyword argument: 'b'"):
165 module.foo(1, b=2)
166 with pytest.raises(TypeError, match="positional-only arguments passed as keyword arguments: 'a', 'b'"):
167 module.foo(a=1, b=2)
168
169
170def test_args_name():

Callers

nothing calls this directly

Calls 2

create_moduleFunction · 0.85
fooMethod · 0.45

Tested by

no test coverage detected