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

Invalid failing example description with hypothesis.stateful.multiple containing single value #3236

Closed
lycantropos opened this issue Feb 21, 2022 · 1 comment · Fixed by #3237
Assignees
Labels
bug something is clearly wrong here

Comments

@lycantropos
Copy link
Contributor

lycantropos commented Feb 21, 2022

On my machine with Python 3.9.5 and hypothesis==6.37.1 (latest at the moment of writing) test case

from hypothesis.stateful import (Bundle,
                                 RuleBasedStateMachine,
                                 multiple,
                                 rule)


class State(RuleBasedStateMachine):
    values = Bundle('values')

    @rule(target=values)
    def create_single_multiple(self):
        return multiple(42)

    @rule(value=values)
    def check_value(self, value):
        assert value != 42


TestCase = State.TestCase

gives

Falsifying example:
    state = State()
    v1 = state.create_single_multiple()
    state.check_value(value=v1)
    state.teardown()

which will succeed because v1 is MultipleResults(values=(42,)) but I think it should be 42, so somewhere in depths of generating failing example for RuleBasedStateMachine we need to handle special case with single-value MultipleResults so the output will be

Falsifying example:
    state = State()
    v1, = state.create_single_multiple()
    # ^ note this comma
    state.check_value(value=v1)
    state.teardown()
@lycantropos
Copy link
Contributor Author

lycantropos commented Feb 21, 2022

I found a place in code which responsible for this behavior

output_assignment = ", ".join(self._last_names(n_output_vars)) + " = "

I've managed to fix this locally by changing it to

            output_vars = self._last_names(n_output_vars)
            output_assignment = (output_vars[0] + ","
                                 if (isinstance(result, MultipleResults)
                                     and n_output_vars == 1)
                                 else ", ".join(output_vars)) + " = "

@lycantropos lycantropos changed the title Invalid failing test case description with multiple containing single value Invalid failing example description with hypothesis.stateful.multiple containing single value Feb 21, 2022
@Zac-HD Zac-HD added the bug something is clearly wrong here label Feb 21, 2022
@Zac-HD Zac-HD self-assigned this Feb 21, 2022
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

Successfully merging a pull request may close this issue.

2 participants