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 Hypothesis for testing #197

Open
brandonwillard opened this issue Nov 23, 2020 · 5 comments
Open

Use Hypothesis for testing #197

brandonwillard opened this issue Nov 23, 2020 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested request discussion testing

Comments

@brandonwillard
Copy link
Member

brandonwillard commented Nov 23, 2020

Given the clear constraints of our problem domain(s), the amount of repetition found within our test suite, the lack of viable test automations, etc., it might be worth using Hypothesis. That seems like a good platform upon which we can build more extensible and robust testing.

@brandonwillard brandonwillard added enhancement New feature or request help wanted Extra attention is needed testing labels Nov 23, 2020
@bergesalexis
Copy link

Hi ! I'm interested in helping out for this. @AlexAndorra is a friend and talked to me about this issue.

I don't have any background in OSS, but have been coding in python for the past 7 years, and I am at the head of a team of 10 data scientist + data engineer in my current job, so I am quite familiar with the importance of test suites, and of proper CI/CD :). I am also already familiar with Hypothesis (we are just starting to use it in my team), I have forked Theano-PyMC and run all the tests locally.

The test suite and code base are already large though, if you had any pointers for me, this would be very much appreciated. Ideally this would be a very small thing to begin with in order to experience your coding guidelines + PR + code review process end to end and be more efficient after that. Many thanks in advance.

@brandonwillard
Copy link
Member Author

#141 and/or #16 are probably the best places to start. They're both rather high-level changes, so you would need to get a broad overview of the elements involved before making changes. Unfortunately, there's no avoiding that.

#16 has more specifics to work with, but #141 is the simplest in terms of the general idea and perhaps the most immediately measurable improvement that could be made between the two.

Neither of them are likely to be "fixed" by the use of Hypothesis, though. Instead, they would serve as a good means of understanding the general situation and perhaps finding some good explicit use cases for Hypothesis.

Otherwise, the tests that seem more immediately appropriate for Hypothesis are probably the ones in tests.tensor.test_basic and tests.tensor.test_basic_scipy. Those tests construct and reuse a lot of value ranges for functions.

If you want to start looking into any of those, you can follow up with questions in the respective issues.

@majidaldo
Copy link

Why specifically Hypothesis when you can have parameterized data generators?

@brandonwillard brandonwillard added question Further information is requested request discussion labels Jan 7, 2022
etellman added a commit to etellman/aesara that referenced this issue Aug 3, 2023
This is a proof of concept for Hypothesis tests. I selected a test that
was easy to convert and replaced the existing test with hard-coded
values with a few tests that use Hypothesis.

Since it was pretty easy to do, I also added tests for complex inputs.
One thing I discovered is that cscalar doesn't work for any of the
numpy functions. Hypothesis inevitably finds a value that can't be
represented precisely and the test fails. All the functions work with
zscalar.

see: aesara-devs#197
@etellman
Copy link

etellman commented Aug 3, 2023

It looks like this is a pretty old issue that hasn't seen much activity lately, but I was interested in it, so I did a quick POC for using Hypothesis.

See #1507

I'm an Aesara novice, so I picked a test that seemed really simple and easy to convert as an example.

@etellman
Copy link

etellman commented Aug 3, 2023

Why specifically Hypothesis when you can have parameterized data generators?

It's a different way of thinking about tests. You specify properties that should always be true and Hypothesis tries to find inputs that make the property false. If it finds something that works, it then tries to narrow down the value to the one that would be most helpful for identifying the problem. For instance, if large values seem to be problematic, Hypothesis tries to find the smallest value that's big enough to make the test fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested request discussion testing
Projects
None yet
Development

No branches or pull requests

4 participants