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

Unspec'd Mock as an argument fails hypothesis health check #491

Closed
dangitall opened this issue Apr 9, 2017 · 3 comments
Closed

Unspec'd Mock as an argument fails hypothesis health check #491

dangitall opened this issue Apr 9, 2017 · 3 comments
Labels
bug something is clearly wrong here

Comments

@dangitall
Copy link

dangitall commented Apr 9, 2017

If I pass an unspec'd mock to a function that is decorated by hypothesis.given then regardless of what the function does, hypothesis flags the function for not returning None.

This snippet demonstrates the problem:

from mock import Mock
from hypothesis import given
import hypothesis.strategies as st

class Bar():
    pass

@given(inp=st.integers())
def test_foo_spec(bar, inp):
    pass

test_foo_spec(Bar())            # Fine
test_foo_spec(Mock(Bar))        # Fine
test_foo_spec(Mock())           # Fails health check

which results in:

Traceback (most recent call last):
  File "test_foo.py", line 14, in <module>
    test_foo_spec(Mock())           # Fails health check
  File "test_foo.py", line 9, in test_foo_spec
    def test_foo_spec(bar, inp):
  File "/Users/dan/.pyenv/versions/3.5.2/envs/test-hypo/lib/python3.5/site-packages/hypothesis/core.py", line 477, in wrapped_test
    runner.run()
  File "/Users/dan/.pyenv/versions/3.5.2/envs/test-hypo/lib/python3.5/site-packages/hypothesis/internal/conjecture/engine.py", line 192, in run
    self._run()
  File "/Users/dan/.pyenv/versions/3.5.2/envs/test-hypo/lib/python3.5/site-packages/hypothesis/internal/conjecture/engine.py", line 313, in _run
    self.new_buffer()
  File "/Users/dan/.pyenv/versions/3.5.2/envs/test-hypo/lib/python3.5/site-packages/hypothesis/internal/conjecture/engine.py", line 76, in new_buffer
    self.test_function(self.last_data)
  File "/Users/dan/.pyenv/versions/3.5.2/envs/test-hypo/lib/python3.5/site-packages/hypothesis/internal/conjecture/engine.py", line 82, in test_function
    self._test_function(data)
  File "/Users/dan/.pyenv/versions/3.5.2/envs/test-hypo/lib/python3.5/site-packages/hypothesis/core.py", line 453, in evaluate_test_data
    ) % (test.__name__, result), HealthCheck.return_value)
  File "/Users/dan/.pyenv/versions/3.5.2/envs/test-hypo/lib/python3.5/site-packages/hypothesis/core.py", line 307, in fail_health_check
    raise FailedHealthCheck(message)
hypothesis.errors.FailedHealthCheck: Tests run under @given should return None, but test_foo_spec returned <Mock name='mock.execute_example()' id='4365662752'> instead.
See https://hypothesis.readthedocs.io/en/latest/healthchecks.html for more information about this. If you want to disable just this health check, add HealthCheck.return_value to the suppress_health_check settings for this test.

I am running 3.5.2 with these packages installed:

click==6.7
hypothesis==3.7.0
mock==2.0.0
pbr==2.0.0
py==1.4.33
pytest==3.0.7
six==1.10.0
spark-parser==1.6.0
uncompyle6==2.9.10
xdis==3.2.4
@DRMacIver
Copy link
Member

Yeah, you're running into a variant of #198 I think. mocks and given don't play very well together right now.

This is unfortunately quite hard to fix given the current semantics of how Hypothesis handles things at the moment and probably requires some major feature changes to work correctly. :-(

For the moment, recommended workaround is to use a spec for your mock.

@Zac-HD Zac-HD added bug something is clearly wrong here duplicate labels Apr 20, 2017
@killthrush
Copy link
Contributor

@DRMacIver - this one good to close? Looks like 3.18.4 worked for my application, just ran through all our test suites.

@Zac-HD
Copy link
Member

Zac-HD commented Aug 18, 2017

Fixed by #779 - thanks to @killthrush!

@Zac-HD Zac-HD closed this as completed Aug 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

No branches or pull requests

4 participants