-
-
Notifications
You must be signed in to change notification settings - Fork 568
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
to implement property based testing.
#4703
Comments
Hey it looks like a interesting issue, i am willing to work on it @prady0t @agriyakhetarpal |
Sure! Please go ahead. Let us know if you need any help. I'll try to find out some tests where hypothesis can be used, it will help you get started. Later you can find more such tests on your own. |
Thanks i will start my work on it @prady0t |
hey @prady0t I thougth maybe I should go by folder inside the |
Hi @RohitP2005, sorry for the late response. Yes you can start by looking into unit tests first. Here's a file where you can start
This file has tests to calculate averages and input-output can be bounded by properties. For a quick example, here's how you can modify the above test : This is a very basic example but demonstrates the use case quite well. What I suggest personally is to make a list of all the test files and start going through each one, implementing hypothesis wherever you can. You can keep checking out the boxes for every file you visited. In this way you will end up going through all the tests and others can also keep track of the progress, otherwise it will be a huge mess. I did something similar while migrating from Here's another example, this class also has a lot of mathematical functions Try to find out clever ways you can use hypothesis in these tests, later you can open up a tracking issue and start working on other files. Here's some reading material that could be helpful : |
Tests within unit folder
22 directories, 159 files |
@prady0t Is the tree checklist okay ? |
Before opening a tracking issue I would suggest going through the above mentioned tests and opening a PR covering both files first. We do not want to flood maintainers with a lot of PRs so it would be great if we group a lot of files together and open PRs when we have a lot of changes (just enough so that they are not difficult to review). Also remember not all tests can be tested like this, in fact the once that I mentioned above might not be the best examples. The goal would be to first identify and list all files that needs such a change, do a lot of changes locally and then open a PR. Would love @agriyakhetarpal @arjxn-py @Saransh-cpp thoughts on this. |
understood , this checklist just shows the available files inside the unit dir, later on reviewing and identifying files which require changes we can remove unecessary files from the checklist . |
One thing to keep in mind is that |
Pybamm migrated from unittest to pytest successfully in the last GSoC cohort. See : https://pybamm.org/gsoc/2024/#migrate-from-unittest-to-pytest-and-improve-pybamms-testing-infrastructure .
What now remains is implementing hypothesis for property based testing. This will ensure more robust tests and will help us find edge cases and bugs more easily.
Here's an example of how we can write tests using hypothesis : https://hypothesis.works/articles/hypothesis-pytest-fixtures/
The goal here would be to identify all the test function that can benefit from property based testing and later using
@given
decorator to give that test function set of properties.Once we have enough tests we can use tools such as oss-fuzz to run it continuously on the cloud. See : https://google.github.io/oss-fuzz/getting-started/new-project-guide/python-lang/#hypothesis
The text was updated successfully, but these errors were encountered: