Skip to content
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

A test fails by raising TypeError exception whenever one of the test function arguments is named 'f' #38

Closed
ramunas opened this issue Mar 22, 2015 · 3 comments

Comments

@ramunas
Copy link

ramunas commented Mar 22, 2015

A test will always fail with the exception that an instance of HypothesisProvided is not callable whenver
one of the arguments test function arguments is named 'f'. For example, given

@given(int, int)
def test_this(x,f):
    assume(x > 1)
    assert x > 1

when run with py.test produces

_________________________________________________________________ test_this __________________________________________________________________

x = HypothesisProvided(value=<class 'int'>), f = HypothesisProvided(value=<class 'int'>)

    def test_this(x=not_set, f=not_set):
>       return f(x=x, f=f)
E       TypeError: 'HypothesisProvided' object is not callable

.hypothesis/eval_source/hypothesis_temporary_module_06cffbd9c8baa4dbbfa21a56fbd77c45e3b770be_0.py:5: TypeError

however, the following

@given(int, int)
def test_this(x,y):
    assume(x > 1)
    assert x > 1

works just fine. Note that I renamed 'f' to 'y'. I get the same outcome regardless of the number of arguments a test function has.

If it help, I'm on platform darwin -- Python 3.4.3 -- py-1.4.26 -- pytest-2.6.4 according to py.test.

@DRMacIver
Copy link
Member

Ha. What a weird bug. You're entirely right, and I'm pretty sure I know how this is happening. I'll try to have a fix out soon.

DRMacIver added a commit that referenced this issue Mar 22, 2015
This fixes issue #38. The problem was that the argument to accept
gets shadowed by an argument to our function so we try to call the
wrong value.

In theory you can still trigger this bug by calling an argument to
your function hypothesis_reflection_internal_name_do_not_use but
you basically have it coming if you do that and I think I'm happy
to say that part of the spec to using @given is don't do that then.
DRMacIver added a commit that referenced this issue Mar 22, 2015
This fixes issue #38. The problem was that the argument to accept
gets shadowed by an argument to our function so we try to call the
wrong value.

In theory you can still trigger this bug by calling an argument to
your function hypothesis_reflection_internal_name_do_not_use but
you basically have it coming if you do that and I think I'm happy
to say that part of the spec to using @given is don't do that then.
@DRMacIver
Copy link
Member

Right. This should be fixed now. If you upgrade to 0.7.2 everything should work.

@DRMacIver
Copy link
Member

Oh, I meant to say by the way, thanks for the well put together bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants