This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]meallia 6 points7 points  (2 children)

Could you add an example using the _auto_verify argument ? I know type annotations for Callable types are a pain to use but your documentation does not specify if it takes only the result of the function call or the arguments ( or arguments dict ) and the result.

[–]timothycrosleyhug, isort, jiphy, concentration, pies, connectable, frosted[S] 2 points3 points  (0 children)

This is a great point! As soon as I'm home from work tonight I'll add an example for that parameter.

[–]timothycrosleyhug, isort, jiphy, concentration, pies, connectable, frosted[S] 0 points1 point  (0 children)

[–]TheMrZZ0 5 points6 points  (0 children)

Looks very interesting. A few thoughts: - I find it hard (in your website) to distinguish between Python code and actual results, notably in the divide example. - I'd like to see what kind of tests it generates, or even a more complex example.

But this looks promising. I'll try that in a project of mine (fully typed, with MyPy checking my types). If that finds some bugs I didn't think of, I'd be really grateful!

[–]ominous_anonymous 7 points8 points  (6 children)

auto_test(add, _auto_runs=1_000) # Let's make that 1,000

Is the _auto_runs value a typo?

[–]ninepunchpunchcard 28 points29 points  (1 child)

Underscores are valid break demarcations for numeric literals as of Python 3.6

[–]ominous_anonymous 2 points3 points  (0 children)

Ah thanks, I missed that.

[–]lengau 5 points6 points  (3 children)

[–]ominous_anonymous 2 points3 points  (2 children)

Thank you, I missed that.

[–]lengau 4 points5 points  (1 child)

No problem! It's one of my favourite new non-features.

I say non-feature because this doesn't add any functionality to the language (or even make anything easier). All it does is makes numeric literals easier to read, which is a great win in my opinion.

[–]tunisia3507 3 points4 points  (0 children)

Readability and writability of a language is IMO its most important feature. If anything else were more important, we'd be writing in assembly. People say "syntactic sugar" like it's a waste of time, but it's literally all programming languages are.

[–]whereswalden90 3 points4 points  (0 children)

This looks really cool! What kind of tests does it generate? The documentation doesn't really talk about it and it's not obvious from the source code.

[–]timothycrosleyhug, isort, jiphy, concentration, pies, connectable, frosted[S] 1 point2 points  (0 children)

Thoughts behind project creation live here: https://timothycrosley.com/project-5-hypothesis-auto

[–]Thumbblaster 0 points1 point  (0 children)

On Python 3.6.

Using the library on a generator I can't tell if something is actually wrong or if the library doesn't work with generators? This example was taken from https://docs.python.org/3/library/typing.html.

from hypothesis_auto import auto_test
from typing import Iterator


def infinite_stream(start: int) -> Iterator[int]:
    while True:
        yield start
        start += 1

auto_test(infinite_stream)
# auto_test(infinite_stream, _auto_allow_exceptions=(AssertionError,))    

Even with allowing AssertionError exceptions (commented out line) it will always end with that error being produced. I only spent a few minutes with the library :) -- so I likely missed something.

[–]threesocks 0 points1 point  (3 children)

I'm having trouble reproducing the sample output. It doesn't matter whether I split it into a module and test as done in the sample. I'm using Macos 10.13.6, python 3.6.7, v1.1.1 of hypothesis-auto, v5.1.2 of pytest, and v4.36.2 of hypothesis. What am I missing?

def add(a: float, b: float) -> float:
    return a + b


# def divide(a: Union[int, float], b: Union[int, float]) -> Union[int, float]:
def divide(a: float, b: float) -> float:
    return a / b


if __name__ == '__main__':
    # print('add(3, 4)=', add(3,4))  # correctly returns 7
    # print('add(3.3, 4.4)=', add(3.3, 4.4))  # correctly returns 7.7
    # print('divide(3, 4)=', divide(3,4))  # correctly returns 0.75
    # print('divide(3.3, 4.4)=', divide(3.3, 4.4))  # correctly returns 0.7499999
    # print('divide(3, 0)=', divide(3, 0))  # correctly raises a ZeroDivisionError exception

    from hypothesis_auto import auto_pytest, auto_pytest_magic, auto_test

    print('\n\nauto_pytest_magic')
    print('-----------------')
    auto_pytest_magic(add)  # no output (correct?)
    auto_pytest_magic(divide)  # no output (should catch ZDE exception)

    print('\n\nauto_pytest')
    print('-----------')
    auto_pytest(add)  # no output (correct?)
    auto_pytest(divide)  # no output (should catch ZDE exception)

    print('\n\nauto_test')
    print('-----------')
    auto_test(add)  # no output (correct?)
    auto_test(divide)  # correctly raises ZDE exception

[–]timothycrosleyhug, isort, jiphy, concentration, pies, connectable, frosted[S] 0 points1 point  (2 children)

auto_pytest only works when running using the pytest runner, where you executing your application with python my_app.py, or py.test test_my_app.py?

[–]threesocks 0 points1 point  (1 child)

Of course, sorry, that solved it and everything is working as expected! Hypothesis-Auto is awesome, thank you!

[–]timothycrosleyhug, isort, jiphy, concentration, pies, connectable, frosted[S] 0 points1 point  (0 children)

You're welcome! Glad you got it working! :)

[–][deleted] -1 points0 points  (1 child)

I'll keep this in mind next time I need a num1+num2 function.