Skip to content

Commit fa0d09e

Browse files
committed
address review
1 parent e118dde commit fa0d09e

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

hypothesis-python/src/hypothesis/internal/conjecture/engine.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -840,20 +840,16 @@ def on_observation(observation: Observation) -> None:
840840
if not self._switch_to_hypothesis_provider:
841841
self.provider.on_observation(observation)
842842

843-
# adding this callback enables observability. Use a nullcontext
844-
# if the backend won't use observability.
845-
return (
846-
with_observation_callback(on_observation)
847-
if (
848-
self.settings.backend != "hypothesis"
849-
# only for lifetime = "test_function" providers (guaranteed
850-
# by this isinstance check)
851-
and isinstance(self.provider, PrimitiveProvider)
852-
# and the provider opted-in to observations
853-
and self.provider.add_observability_callback
854-
)
855-
else nullcontext()
856-
)
843+
if (
844+
self.settings.backend != "hypothesis"
845+
# only for lifetime = "test_function" providers (guaranteed
846+
# by this isinstance check)
847+
and isinstance(self.provider, PrimitiveProvider)
848+
# and the provider opted-in to observations
849+
and self.provider.add_observability_callback
850+
):
851+
return with_observation_callback(on_observation)
852+
return nullcontext()
857853

858854
def run(self) -> None:
859855
with (

hypothesis-python/src/hypothesis/internal/conjecture/providers.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,6 @@ def on_observation(self, observation: TestCaseObservation) -> None: # noqa: B02
587587
during |Phase.reuse| or |Phase.shrink|, or because Hypothesis switched
588588
to the standard Hypothesis backend after this backend raised too many
589589
|BackendCannotProceed| exceptions.
590-
591-
By default, observability will not be enabled for backends which do not
592-
override this method. By overriding this method, any test which sets
593-
|settings.backend| to this provider will automatically enable observability.
594590
"""
595591

596592
def span_start(self, label: int, /) -> None: # noqa: B027 # non-abstract noop

hypothesis-python/tests/conjecture/test_alt_backend.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -741,23 +741,21 @@ def on_observation(self, observation: Observation) -> None:
741741
self.expected = "per_test_case_context_manager"
742742

743743

744+
@temp_register_backend("observation", ObservationProvider)
744745
def test_on_observation_alternates():
745-
with temp_register_backend("observation", ObservationProvider):
746+
@given(st.integers())
747+
@settings(backend="observation")
748+
def f(n):
749+
pass
746750

747-
@given(st.integers())
748-
@settings(backend="observation")
749-
def f(n):
750-
pass
751-
752-
f()
751+
f()
753752

754753

754+
@temp_register_backend("observation", TrivialProvider)
755755
def test_on_observation_no_override():
756-
with temp_register_backend("observation", TrivialProvider):
756+
@given(st.integers())
757+
@settings(backend="observation")
758+
def f(n):
759+
assert TESTCASE_CALLBACKS == []
757760

758-
@given(st.integers())
759-
@settings(backend="observation")
760-
def f(n):
761-
assert TESTCASE_CALLBACKS == []
762-
763-
f()
761+
f()

0 commit comments

Comments
 (0)