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

Make Flaky into an ExceptionGroup #4043

Merged
merged 8 commits into from
Jul 13, 2024

Conversation

jobh
Copy link
Contributor

@jobh jobh commented Jul 12, 2024

This PR makes Flaky into an ExceptionGroup to improve presentation of flaky failures. Closes #4040.

As usual, There Were Complications. Basically because an ExceptionGroup is not allowed to have an empty group; so a straightforward replacement is not possible.

On the plus side, I think the reworked Flaky is more expressive by differentiating two different kinds of flakiness (replay inconsistencies vs. inconsistent data generation), and it does improve reporting of flaky errors detected by the engine by adding full exceptions on the way out.

HypothesisException (via _Trimmable)
    |
    +Flaky              Base class for all flakiness (not currently raised anywhere).
       |
       + FlakyData      Raised to user. Conjecture detects inconsistent data generation.
       |
       + FlakyReplay    Internal. Conjecture detects flaky replay failure, but has only InterestingOrigins.
       |
       + FlakyFailure   Raised to user. ExceptionGroup, possibly constructed from a FlakyReplay.

A simpler flat alternative is this, with the only drawback being that InconsistentData (renamed from FlakyData) is no longer Flaky. I think I actually prefer this version, but I don't know how you feel about this drawback — is it even acceptable for a minor revision, do users ever catch Flaky? — so the implemented version is the one above.

HypothesisException (via _Trimmable)
    |
    + Flaky                Raised to user. ExceptionGroup, possibly constructed from a FlakyReplay.
    |
    + FlakyReplay          Internal. Conjecture detects flaky replay failure, but has only InterestingOrigins.
    |
    + InconsistentData     Raised to user. Conjecture detects inconsistent data generation.

@jobh jobh requested a review from Zac-HD as a code owner July 12, 2024 12:37
@jobh jobh force-pushed the flaky-exceptiongroup branch 4 times, most recently from fec4b0d to 342c677 Compare July 12, 2024 13:57
@jobh jobh force-pushed the flaky-exceptiongroup branch from 342c677 to 522274d Compare July 12, 2024 14:00
@tybug
Copy link
Member

tybug commented Jul 12, 2024

is it even acceptable for a minor revision, do users ever catch Flaky?

Looks pretty rare, with the majority being schemathesis: https://github.com/search?q=%22except+Flaky%3A%22+OR+%22except+Flaky+as%22+language%3Apython&type=code

That said, I definitely have some local research code that catches Flaky...but I knew I was flying close to the sun with that one.

@Zac-HD
Copy link
Member

Zac-HD commented Jul 12, 2024

Seems rare, but while I share your preference for the flat version I think we should continue to support Flaky - power-users and researchers are still users, and I'm generally comfortable taking on some more maintainece burden to make using Hypothesis delightful 🙂

@jobh
Copy link
Contributor Author

jobh commented Jul 12, 2024

So be it 😇 Ready for review then! No rush - I'm starting my summer vacation today, and will be on and off depending on weather. Hopefully mostly off 😁

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.

I want to play around and compare the before-and-after reporting for some examples before we merge, but this looks great so far 😁

self._interesting_origins = interesting_origins


class FlakyData(Flaky):
Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned that users will think we're reporting an internal error rather than something they need to fix, but I can't think of any name that wouldn't 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Naming is hard! I went through FlakyGeneration plus some variants of InconsistentX and IndetermisticX, and not at all sure I settled for the best.

Copy link
Contributor Author

@jobh jobh Jul 12, 2024

Choose a reason for hiding this comment

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

FlakyStrategy? And rename the other one to FlakyExecution, for symmetry?

Edit: maybe it's bad form to like my own comment, but I think these names would better. FlakyExecution and FlakyStrategy.

Copy link
Member

Choose a reason for hiding this comment

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

I do like FlakyReplay as a concise and evocative name; for the other I've gone with FlakyStrategyDefinition which is more verbose but does seem to point to the thing-which-is-flaky.

hypothesis-python/src/hypothesis/errors.py Show resolved Hide resolved
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.

Played around a bit more and I'm very happy with this; I've also pulled out a cross-backend-specific thing from #4034 which will help us and our users debug such issues.

Thanks again, @jobh!

self._interesting_origins = interesting_origins


class FlakyData(Flaky):
Copy link
Member

Choose a reason for hiding this comment

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

I do like FlakyReplay as a concise and evocative name; for the other I've gone with FlakyStrategyDefinition which is more verbose but does seem to point to the thing-which-is-flaky.

@Zac-HD Zac-HD enabled auto-merge July 13, 2024 19:35
@Zac-HD Zac-HD merged commit 317958d into HypothesisWorks:master Jul 13, 2024
58 checks passed
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.

Change Flaky to be an ExceptionGroup
3 participants