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

CrossHairInternal: Not in a statespace context error on tests with Pytest fixtures #24

Open
Zac-HD opened this issue Jan 26, 2025 · 0 comments

Comments

@Zac-HD
Copy link

Zac-HD commented Jan 26, 2025

from unittest.mock import Mock
import pytest
from hypothesis import settings, given, strategies as st

@pytest.fixture(scope="module")  # or any other scope
def mock_fixture():
    return Mock()

@settings(backend="crosshair")
@given(xs=st.integers())
def test(mock_fixture, xs):
    assert xs != 123456789

mock_fixture is of course completely pointless, but with the crosshair backend causes the following error:

Traceback (most recent call last):
  ...
  File ".../repro.py", line 15, in test
    @given(xs=integers())
  File "hypothesis/core.py", line 1829, in wrapped_test
    raise the_error_hypothesis_found
  File "crosshair/libimpl/builtinslib.py", line 1238, in __hash__
    return self.__index__().__hash__()
  File "crosshair/libimpl/builtinslib.py", line 1260, in __index__
    space = context_statespace()
  File "crosshair/statespace.py", line 269, in context_statespace
    raise CrossHairInternal("Not in a statespace context")
crosshair.util.CrossHairInternal: Not in a statespace context

I haven't bisected, but this error is new from somewhere in the crosshair-tool .74 -> .82 and/or hypothesis-crosshair .16 -> .19 upgrade range.

links: HypothesisWorks/hypothesis#4190, which is an update to HypothesisWorks/hypothesis#4034

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

No branches or pull requests

1 participant