Skip to content

Add PrimitiveProvider.on_observation #4416

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

Merged
merged 7 commits into from
May 31, 2025

Conversation

tybug
Copy link
Member

@tybug tybug commented May 27, 2025

I'm finding this useful as a "post test-case callback" in hypofuzz. I'm hoping to put things like observation.metadata.data_status: Status and observation.metadata.choice_nodes in here, and replace any manual inspection of ConjectureData from HypofuzzProvider.

@tybug tybug requested review from DRMacIver and Zac-HD as code owners May 27, 2025 22:48
@tybug tybug force-pushed the provider-on-observability branch from 33094e2 to b2be76d Compare May 27, 2025 22:50
Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per comment below, maybe we can use Provider.observe_test_case() instead of this new mechanism?

@Zac-HD
Copy link
Member

Zac-HD commented May 29, 2025

unrelated note: this line suggests that monkeypatching OBSERVABILITY_COLLECT_COVERAGE in the defining module won't work; we should probably import it differently since we've documented that it's patchable (and maybe a test???)

@tybug tybug mentioned this pull request May 31, 2025
4 tasks
Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, let's ship it!

Comment on lines 845 to 856
return (
with_observation_callback(on_observation)
if (
self.settings.backend != "hypothesis"
# only for lifetime = "test_function" providers (guaranteed
# by this isinstance check)
and isinstance(self.provider, PrimitiveProvider)
# and the provider opted-in to observations
and self.provider.add_observability_callback
)
else nullcontext()
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems cleaner as an if-statement and two returns than a ternary expression and one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting! I disagree, but only very weakly

@tybug tybug enabled auto-merge May 31, 2025 19:19
@tybug tybug merged commit ab90309 into HypothesisWorks:master May 31, 2025
59 checks passed
@tybug tybug deleted the provider-on-observability branch June 1, 2025 02:27
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

Successfully merging this pull request may close these issues.

2 participants