{"record":{"id":"0673f8993e25fb54","repo":"jax-ml/jax","slug":"sharded-hypothesis-runner-does-not-support-data","errorCode":null,"errorMessage":"Sharded hypothesis runner does not support `data()` inside `@given`. All parameters must be drawn before the test body is called. Consider using `@composite` instead.","messagePattern":"Sharded hypothesis runner does not support `data\\(\\)` inside `@given`\\. All parameters must be drawn before the test body is called\\. Consider using `@composite` instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/hypothesis_test_util.py","lineNumber":127,"sourceCode":"\n\ndef _apply_sharding_to_tests(test_runner):\n\n  shards_index_iter = itertools.cycle(range(_TEST_TOTAL_SHARDS))\n  for name in dir(test_runner):\n    if name.startswith(\"test\"):\n      test = getattr(test_runner, name)\n      if detection.is_hypothesis_test(test):\n        handle = test.hypothesis\n        assert isinstance(handle, hp.core.HypothesisHandle)\n        # `@given(..., data())` is not supported because:\n        # - Sharding requires known values for all drawn parameters.\n        # - The test body must be called given the sharding.\n        # - Using `data()`, some or all parameters are not known until the test\n        #   body is called.\n        for val in handle._given_kwargs.values():\n          if isinstance(val, hps_internal_core.DataStrategy):\n            raise ValueError(\n                \"Sharded hypothesis runner does not support `data()` inside\"\n                \" `@given`. All parameters must be drawn before the test body\"\n                \" is called. Consider using `@composite` instead.\"\n            )\n        handle.inner_test = _shard_aware_hypothesis_inner_test(\n            handle.inner_test\n        )\n      else:\n        # If the tests are not hypothesis tests (or we are not sharding\n        # hypothesis tests), we can just assign them to shards in a round-robin\n        # fashion.\n        if _TEST_TOTAL_SHARDS > 1:\n          shard_index = next(shards_index_iter)\n          setattr(test_runner, name, _shard_aware_test(test, shard_index))\n\n\nclass HypothesisShardedTestCase(jtu.JaxTestCase):\n  \"\"\"Runs Hypothesis tests in a sharded manner.","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/hypothesis_test_util.py#L109-L145","documentation":"Raised by JAX's sharding-aware test harness (hypothesis_test_util) when a @given-based test class is configured for sharded execution but its @given includes hypothesis's data() strategy. Sharding needs all drawn parameters known before the test body runs, and data() defers draws into the body, so the combination is rejected with a suggestion to use @composite.","triggerScenarios":"Adding data() to the @given arguments of a test in a test class that inherits the sharded hypothesis runner (internal JAX test infra), e.g. @given(st.data(), x=st.floats()).","commonSituations":"Contributing tests to JAX (or projects reusing its test util) where sharding is enabled in CI; converting property tests to draw dependent values lazily via data().","solutions":["Replace data() with explicit strategies and @composite to generate dependent values up front","Draw all parameters in @given before the body runs","If sharding isn't needed for that test, run it outside the sharded runner/base class"],"exampleFix":"# before\n@given(data=st.data())\ndef test_foo(self, data):\n    x = data.draw(st.floats())\n    ...\n# after\n@st.composite\ndef xs(draw):\n    return draw(st.floats())\n@given(x=xs())\ndef test_foo(self, x):\n    ...","handlingStrategy":"validation","validationCode":"# in test setup: reject data() before enabling sharding\nfrom hypothesis.internal.core import DataStrategy  # illustrative\nfor k, strat in given_kwargs.items():\n    if type(strat).__name__ == 'DataStrategy':\n        raise ValueError('replace data() with @composite for sharded tests')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use @composite for dependent draws instead of data()","Keep @given draws static when sharding tests"],"tags":["jax","testing","hypothesis","sharding"],"backgroundTag":"hypothesis-data-strategy-unsupported","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}