Skip to content

NotImplementedError: This should never happen in a test chaining st.datetimes() #3755

@honno

Description

@honno

For the following test

# bad_test.py
from datetime import datetime
from hypothesis import given, strategies as st, assume


@given(start_date=st.datetimes(), data=st.data())
def test_foo(start_date, data):
    end_date = data.draw(st.datetimes(min_value=start_date))
    assert False

you will sometimes give you a scary NotImplementedError: This should never happen error raised in hypothesis.internal.conjecture.shrinker.

Full traceback
Traceback (most recent call last):
  File "bad_test.py", line 31, in <module>
    test_foo()
  File "bad_test.py", line 26, in test_foo
    def test_foo(start_date, data):
  File ".../hypothesis/hypothesis-python/src/hypothesis/core.py", line 1471, in wrapped_test
    raise the_error_hypothesis_found
  File ".../hypothesis/hypothesis-python/src/hypothesis/core.py", line 1438, in wrapped_test
    state.run_engine()
  File ".../hypothesis/hypothesis-python/src/hypothesis/core.py", line 1006, in run_engine
    runner.run()
  File ".../hypothesis/hypothesis-python/src/hypothesis/internal/conjecture/engine.py", line 461, in run
    self._run()
  File ".../hypothesis/hypothesis-python/src/hypothesis/internal/conjecture/engine.py", line 874, in _run
    self.shrink_interesting_examples()
  File ".../hypothesis/hypothesis-python/src/hypothesis/internal/conjecture/engine.py", line 939, in shrink_interesting_examples
    self.shrink(example, predicate)
  File ".../hypothesis/hypothesis-python/src/hypothesis/internal/conjecture/engine.py", line 971, in shrink
    s.shrink()
  File ".../hypothesis/hypothesis-python/src/hypothesis/internal/conjecture/shrinker.py", line 442, in shrink
    self.explain()
  File ".../hypothesis/hypothesis-python/src/hypothesis/internal/conjecture/shrinker.py", line 578, in explain
    raise NotImplementedError("This should never happen")
NotImplementedError: This should never happen

I never see this issue once .hypothesis is generated, but if it's not (e.g. if you keep on deleting it before running the tests again) then I see it more often than not.

This looks to be an issue from #3749, as I get this issue on the latest release/master, but not on say the 6.84.2 release just before the aforementioned explain-mode patch.

This was found in a PyCon UK "sprint" I ran with someone who's never used the library before—not the best timing 😅 Huge kudos to @End-of-Eternity for giving me a minimal reproducer!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething is clearly wrong here

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions