-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
check that tests that are partial staticmethods are supported #5701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix collection of ``staticmethod`` objects defined with ``functools.partial``. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -78,7 +78,7 @@ def num_mock_patch_args(function): | |||||
) | ||||||
|
||||||
|
||||||
def getfuncargnames(function, is_method=False, cls=None): | ||||||
def getfuncargnames(function, *, name: str = "", is_method=False, cls=None): | ||||||
"""Returns the names of a function's mandatory arguments. | ||||||
|
||||||
This should return the names of all function arguments that: | ||||||
|
@@ -91,11 +91,12 @@ def getfuncargnames(function, is_method=False, cls=None): | |||||
be treated as a bound method even though it's not unless, only in | ||||||
the case of cls, the function is a static method. | ||||||
|
||||||
The name parameter should be the original name in which the function was collected. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "original name" of what? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could mention that the default is |
||||||
|
||||||
@RonnyPfannschmidt: This function should be refactored when we | ||||||
revisit fixtures. The fixture mechanism should ask the node for | ||||||
the fixture names, and not try to obtain directly from the | ||||||
function object well after collection has occurred. | ||||||
|
||||||
""" | ||||||
# The parameters attribute of a Signature object contains an | ||||||
# ordered mapping of parameter names to Parameter instances. This | ||||||
|
@@ -118,11 +119,14 @@ def getfuncargnames(function, is_method=False, cls=None): | |||||
) | ||||||
and p.default is Parameter.empty | ||||||
) | ||||||
if not name: | ||||||
name = function.__name__ | ||||||
|
||||||
# If this function should be treated as a bound method even though | ||||||
# it's passed as an unbound method or function, remove the first | ||||||
# parameter name. | ||||||
if is_method or ( | ||||||
cls and not isinstance(cls.__dict__.get(function.__name__, None), staticmethod) | ||||||
cls and not isinstance(cls.__dict__.get(name, None), staticmethod) | ||||||
): | ||||||
arg_names = arg_names[1:] | ||||||
# Remove any names that will be replaced with mocks. | ||||||
|
@@ -245,7 +249,7 @@ def get_real_method(obj, holder): | |||||
try: | ||||||
is_method = hasattr(obj, "__func__") | ||||||
obj = get_real_func(obj) | ||||||
except Exception: | ||||||
except Exception: # pragma: no cover | ||||||
return obj | ||||||
if is_method and hasattr(obj, "__get__") and callable(obj.__get__): | ||||||
obj = obj.__get__(holder) | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.