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

Use a timedelta for the deadline setting #1900

Closed
Zac-HD opened this issue Mar 28, 2019 · 2 comments · Fixed by #1920
Closed

Use a timedelta for the deadline setting #1900

Zac-HD opened this issue Mar 28, 2019 · 2 comments · Fixed by #1920
Labels
legibility make errors helpful and Hypothesis grokable

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Mar 28, 2019

The deadline setting is given as a number of milliseconds, but users could mistake this number for seconds or microseconds. Fortunately, Python has a timedelta type which can easily express durations - it would be good to accept timedeltas as values for the deadline setting, and convert numeric deadlines to timedeltas for unambiguous display.

That would mean:

  • Modifying the hypothesis._settings._validate_deadline function to accept timedeltas as well as numbers, and to return a timedelta
  • Make the default value for the deadline setting a timedelta
  • Calculate runtime in hypothesis/core.py as a timedelta, instead of a number of milliseconds, so that the comparison works (ctrl-f for deadline to find this)
  • Add a test in hypothesis-python/tests/cover/test_settings.py that passes a timedelta as a deadline, to check that it works and get full coverage
  • [optionally] create a subclass of datetime.timedelta that gives the __repr__ in terms of milliseconds, and use it in hypothesis._settings._validate_deadline (only). e.g.:
class timedelta_ms(datetime.timedelta):
    def __repr__(self):
        t = self.total_seconds() * 1000
        if t == int(t):
            return "timedelta(milliseconds=%d)" % int(t)
        return datetime.timedelta.__repr__(self)
@Zac-HD Zac-HD added good first issue legibility make errors helpful and Hypothesis grokable labels Mar 28, 2019
@dtfrancisco
Copy link
Contributor

I would like to take a shot at this.

@Zac-HD
Copy link
Member Author

Zac-HD commented Apr 3, 2019

Go for it! Per our usual policy, we'll reserve this issue for you for the next week 😄

Make sure you check the contributing guide - you'll need to add your name to the list of authors, and add a RELEASE.rst file, then go through the points above. If in doubt, open a work-in-progress pull request and I'll be happy to review it and help out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legibility make errors helpful and Hypothesis grokable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants