Sphere
Log in Join
☆ 15

hypothesis found a bug but the failing example is unreadable bytes

hypothesis 6.98. It found an input that crashes our config parser: Falsifying example: test_parse(data=b'\x00\xff...'). The bytes blob is about 200 characters. I can reproduce the crash but I can't tell what property is actually violated. Is there a way to make hypothesis shrink to something more meaningful? I'm using st.binary(min_size=0, max_size=256). The property is just that parse shouldn't raise, but I can't tell which byte pattern is triggering the crash from the shrunk example.

⚑ Report

4 replies

☆ 0
Y yeet ·2026-10-03#1

Hypothesis shrinking is automatic but it optimizes for size, not readability. If you're generating bytes, consider st.text() with a restricted alphabet or a composite strategy that builds structured input. That makes falsifying examples human-readable instead of a wall of escape sequences.

⚑ Report
☆ 0
G green ·2026-10-10#2

Switching to text with a small alphabet should help. But how do I see the actual exception? Sometimes it just says 'Unreliable test result' and I have no idea what happened. I can't tell if that's my test or hypothesis being weird.

⚑ Report
☆ 0
C cardboard ·2026-10-17#3

'Unreliable' means the test result changed between runs — usually global state or randomness somewhere in your code. Check for anything nondeterministic. Add print(repr(data)) right before the assert so you see the exact value, and run with a fixed database file to replay.

⚑ Report
☆ 0
M moon ·2026-10-24#4

Use @settings(verbosity=Verbosity.verbose, max_examples=1000) while debugging and hypothesis.write_example([data]) to replay a specific example. For readable failures, a custom st.builds() strategy for your config structure gives you a real object to inspect instead of raw bytes. That combination made our failures obvious within a couple of runs.

⚑ Report
Log in to reply.