Skip to content

Hypothesis property-based testing demo #2732

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

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft

Hypothesis property-based testing demo #2732

wants to merge 1 commit into from

Conversation

alexrudd2
Copy link
Collaborator

Just a demo for now; I want to find some more complex testing that hypothesis would be good at.

hypothesis is a property-based testing library. It does semi-automatic property-based testing to find edge cases easier than manual test cases. I think this would be especially useful for testing encoding/decoding or various message roundtrips.

from pymodbus.client.mixin import ModbusClientMixin as mixin


word_order_strategy = st.one_of(st.just("big"), st.just("little"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to @pytest.mark.parameterize but it will mix in the big/little with testing a range of values.


word_order_strategy = st.one_of(st.just("big"), st.just("little"))

@given(value=st.integers(min_value=-(2**15), max_value=2**15 - 1), word_order=word_order_strategy)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will perform ~100 tests with strategically chosen numbers in the given range to stress-test the function. (like fuzzing)

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

Successfully merging this pull request may close these issues.

1 participant