MCPcopy
hub / github.com/pytest-dev/pytest / _call_with_optional_argument

Function _call_with_optional_argument

src/_pytest/python.py:723–732  ·  src/_pytest/python.py::_call_with_optional_argument

Call the given function with the given argument if func accepts one argument, otherwise calls func without arguments.

(func, arg)

Source from the content-addressed store, hash-verified

721
722
723def _call_with_optional_argument(func, arg) -> None:
724 class="st">"""Call the given function with the given argument if func accepts one argument, otherwise
725 calls func without arguments.class="st">"""
726 arg_count = func.__code__.co_argcount
727 if inspect.ismethod(func):
728 arg_count -= 1
729 if arg_count:
730 func(arg)
731 else:
732 func()
733
734
735def _get_first_non_fixture_func(obj: object, names: Iterable[str]) -> object | None:

Callers 5

setupMethod · 0.85

Calls 1

funcFunction · 0.50

Tested by

no test coverage detected