Skip to content

Commit

Permalink
Merge pull request #3246 from Zac-HD/fix-proxies-regression
Browse files Browse the repository at this point in the history
Fix regression in `@proxies`
  • Loading branch information
Zac-HD authored Mar 3, 2022
2 parents 79cafec + 990c979 commit 4e422a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RELEASE_TYPE: patch

This patch fixes a regression where the bound inner function
(``your_test.hypothesis.inner_test``) would be invoked with positional
arguments rather than passing them by name, which broke
:pypi:`pytest-asyncio` (:issue:`3245`).
8 changes: 4 additions & 4 deletions hypothesis-python/src/hypothesis/internal/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def function_digest(function):
return hasher.digest()


def get_signature(target):
def get_signature(target, *, follow_wrapped=True):
# Special case for use of `@unittest.mock.patch` decorator, mimicking the
# behaviour of getfullargspec instead of reporting unusable arguments.
patches = getattr(target, "patchings", None)
Expand Down Expand Up @@ -119,7 +119,7 @@ def get_signature(target):
return sig.replace(
parameters=[v for k, v in sig.parameters.items() if k != "self"]
)
return inspect.signature(target)
return inspect.signature(target, follow_wrapped=follow_wrapped)


def arg_is_required(param):
Expand Down Expand Up @@ -605,7 +605,7 @@ def define_function_signature_from_signature(name, docstring, signature):
]

def accept(f):
fsig = inspect.signature(f)
fsig = inspect.signature(f, follow_wrapped=False)
must_pass_as_kwargs = []
invocation_parts = []
for p in pos_args:
Expand Down Expand Up @@ -687,7 +687,7 @@ def proxies(target: "T") -> Callable[[Callable], "T"]:
replace_sig = define_function_signature_from_signature(
target.__name__.replace("<lambda>", "_lambda_"), # type: ignore
target.__doc__,
get_signature(target),
get_signature(target, follow_wrapped=False),
)

def accept(proxy):
Expand Down
11 changes: 11 additions & 0 deletions hypothesis-python/tests/nocover/test_modify_inner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,14 @@ def invalid_test(x):
invalid_test()

assert invalid_test.hypothesis.inner_test == original


def test_invokes_inner_function_with_args_by_name():
# Regression test for https://github.com/HypothesisWorks/hypothesis/issues/3245
@given(st.integers())
def test(x):
pass

f = test.hypothesis.inner_test
test.hypothesis.inner_test = wraps(f)(lambda **kw: f(**kw))
test()

0 comments on commit 4e422a8

Please sign in to comment.