Skip to content

Commit 5862716

Browse files
authored
Merge pull request #4445 from tybug/observability-reproduction-decorator
Fix all failing examples not having `reproduction_decorator`
2 parents 3303ed8 + 15c4afe commit 5862716

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RELEASE_TYPE: patch
2+
3+
Fixes ``reproduction_decorator`` being missing under :ref:`hypothesis-specific metadata <observability-hypothesis-metadata>` in many :ref:`observability <observability>` observations, when it should have been present.

hypothesis-python/docs/reference/integrations.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ Test case
168168
.. jsonschema:: ./schema_observations.json#/oneOf/0
169169
:hide_key: /additionalProperties, /type
170170

171+
.. _observability-hypothesis-metadata:
172+
171173
Hypothesis metadata
172174
+++++++++++++++++++
173175

hypothesis-python/src/hypothesis/internal/observability.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,12 @@ def make_testcase(
306306

307307
if status is not None and isinstance(status, Status):
308308
status = status_map[status]
309+
if status is None:
310+
status = status_map[data.status]
309311

310312
return TestCaseObservation(
311313
type="test_case",
312-
status=status if status is not None else status_map[data.status],
314+
status=status,
313315
status_reason=status_reason,
314316
representation=representation,
315317
arguments={

hypothesis-python/tests/cover/test_observability.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,30 @@ def test_fails(x, y):
281281
assert observation.arguments == {"x": 1, "y": 0}
282282

283283

284+
@pytest.mark.skipif(
285+
PYPY or IN_COVERAGE_TESTS, reason="coverage requires sys.settrace pre-3.12"
286+
)
287+
def test_all_failing_observations_have_reproduction_decorator():
288+
@given(st.integers())
289+
def test_fails(x):
290+
raise AssertionError
291+
292+
with capture_observations() as observations:
293+
# NOTE: For compatibility with Python 3.9's LL(1)
294+
# parser, this is written as a nested with-statement,
295+
# instead of a compound one.
296+
with pytest.raises(AssertionError):
297+
test_fails()
298+
299+
# all failed test case observations should have reprodution_decorator
300+
for observation in [
301+
tc for tc in observations if tc.type == "test_case" and tc.status == "failed"
302+
]:
303+
decorator = observation.metadata.reproduction_decorator
304+
assert decorator is not None
305+
assert decorator.startswith("@reproduce_failure")
306+
307+
284308
@settings(max_examples=20, stateful_step_count=5)
285309
class UltraSimpleMachine(RuleBasedStateMachine):
286310
value = 0

0 commit comments

Comments
 (0)