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

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

Closed
honno opened this issue Sep 30, 2023 · 2 comments · Fixed by #3758
Closed

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

honno opened this issue Sep 30, 2023 · 2 comments · Fixed by #3758
Labels
bug something is clearly wrong here

Comments

@honno
Copy link
Member

honno commented Sep 30, 2023

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!

@Zac-HD Zac-HD added the bug something is clearly wrong here label Oct 1, 2023
@End-of-Eternity
Copy link

Glad I could help :)

@Zac-HD
Copy link
Member

Zac-HD commented Oct 1, 2023

Thanks from me as well! The fix should be released in half an hour or so 😁

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.

3 participants