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

Print seed on test failure to aid reproduction #860

Merged
merged 12 commits into from Sep 19, 2017
Merged

Conversation

DRMacIver
Copy link
Member

Users often find themselves in one or more of the following scenarios:

  • They have data types with very bad reprs
  • They are using Hypothesis features that currently don't play well with @example.
  • Their CI setup doesn't interact brilliantly with the Hypothesis example database.

This can make it annoying to impossible to reproduce failures from CI locally.

This PR aims to mitigate that: When a test fails, if the random seed required to reproduce that test was not already set deterministically (with @seed or derandomize=True or with the command line argument I'll mention in a moment), Hypothesis will print out the seed it used along with instructions on how to use it to reproduce the example.

In order to make that information more readily useful and allow reproducing examples without editing the source code, this also adds a command line flag for pytest users to pass the seed explicitly.

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 - this is the kind of important but unglamorous work that distinguishes really cool projects from really useful projects. Thanks to Smarkets for funding it!

RELEASE.rst Outdated
* pytest users can specify a seed to use for ``@given`` based tests by passing
the ``--hypothesis-seed`` command line argument.
* When a test fails, either with a health check failure or a falsifying example,
Hypothesis will print out a seed that lead to that failure if the test is not
Copy link
Member

Choose a reason for hiding this comment

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

"lead" -> "led" or "leads"; or just reread the whole sentence and decide on a tense.

@Zac-HD
Copy link
Member

Zac-HD commented Sep 15, 2017

Not much more to say really - it's a solid and useful change, but probably not something to write a blog post about 😄

@DRMacIver
Copy link
Member Author

DRMacIver commented Sep 15, 2017

Not much more to say really - it's a solid and useful change, but probably not something to write a blog post about 😄

I am in fact scheduled to write a blog post about it. 😉

More specifically, Smarkets are paying for a bunch of feature dev, mostly around making Hypothesis performance problems more legible (this fits into that because it lets you reproduce the exact scenario that lead to a failed health check, which I totally forgot to mention as a use case in the preamble above!). Once I've finished all of them I'm going to write a blog post about the whole set of work and the motivations leading up to it.

@DRMacIver DRMacIver force-pushed the DRMacIver/print-seed branch 2 times, most recently from 64cf907 to 2b0c94c Compare September 17, 2017 16:19
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.

None yet

2 participants