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

Cannot unpack non-iterable MultipleResults object #2311

Closed
vxgmichel opened this issue Jan 8, 2020 · 2 comments
Closed

Cannot unpack non-iterable MultipleResults object #2311

vxgmichel opened this issue Jan 8, 2020 · 2 comments
Labels
bug

Comments

@vxgmichel
Copy link
Contributor

@vxgmichel vxgmichel commented Jan 8, 2020

Hi !

I ran into a problem with the falsifying examples produced by stateful testing with multiple results.

Consider the following state machine:

from hypothesis.stateful import Bundle, RuleBasedStateMachine
from hypothesis.stateful import rule, multiple, initialize


class DatabaseComparison(RuleBasedStateMachine):

    values = Bundle("values")

    @initialize(target=values)
    def produce(self):
        return multiple(1, 2, 3)

    @rule(v=values)
    def check(self, v):
        assert v == 1


TestDBComparison = DatabaseComparison.TestCase

It legitimately fails with the following info:

E       AssertionError: assert 3 == 1

test_hypo.py:16: AssertionError
---------------------- Hypothesis --------------------
Falsifying example:
state = DatabaseComparison()
v1, v2, v3 = state.produce()
state.check(v=v3)
state.teardown()

Let's put the falsifying example into a dedicated test:

def test_reproduce():
    state = DatabaseComparison()
    v1, v2, v3 = state.produce()
    state.check(v=v3)
    state.teardown()

The problem is that the test fails with the following error:

    def test_reproduce():
        state = DatabaseComparison()
>       v1, v2, v3 = state.produce()
E       TypeError: cannot unpack non-iterable MultipleResults object

test_hypo.py:24: TypeError

This can be fixed with the following change:

def test_reproduce_fixed():
    state = DatabaseComparison()
    v1, v2, v3 = state.produce().values
    state.check(v=v3)
    state.teardown()

Which does produce the right error:

E       assert 3 == 1

test_hypo.py:16: AssertionError
vxgmichel added a commit to python-trio/hypothesis-trio that referenced this issue Jan 8, 2020
@Zac-HD Zac-HD added the bug label Jan 8, 2020
@Zac-HD

This comment has been minimized.

Copy link
Member

@Zac-HD Zac-HD commented Jan 8, 2020

Definitely a bug - fortunately it's easy to fix, just adding an __iter__ method to

@attr.s()
class MultipleResults:
values = attr.ib()

pasting your test case above into hypothesis-python/tests/cover/test_stateful.py.

Would you like to open a PR, so python-trio/hypothesis-trio#5 doesn't need a workaround?

@vxgmichel

This comment has been minimized.

Copy link
Contributor Author

@vxgmichel vxgmichel commented Jan 8, 2020

@Zac-HD

Would you like to open a PR, so python-trio/hypothesis-trio#5 doesn't need a workaround?

Done: #2312 :)

@Zac-HD Zac-HD closed this Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.