-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Parameterize tests #6525
Comments
I've done a pass over the tests, and created #6526. Do you think there is still more work to be done? |
I think there are more tests that can be parametrized. I left a comment with some of them on your pull request. |
I've applied your suggestions. |
All three PRs have now been merged. Is there still more work to be done? |
Possibly. I haven't looked through all of the test files, but there's probably a few more that could be parametrized. |
If there's nothing specific, then it's hard to know when this is done. I've done another pass over the tests, and created PR #6634. I'm going to say that PR resolves this. |
Thanks both for the issue and PRs! Parametrising means we get more test cases, which is good because each runs in isolation. Before this issue was opened, there were 3,177 test cases (Python 3.10/Ubuntu):
https://github.com/python-pillow/Pillow/actions/runs/2904499282/jobs/4622327543 After the last PR #6634 was closed, we're at 3,969 test cases:
https://github.com/python-pillow/Pillow/actions/runs/3176175582/jobs/5175163150 Obviously some of these new tests are from other PRs, but most of these 792 will be from parametrising. 🚀 |
I've noticed that some of the parameters use tuples, and some use lists. I don't think it makes a difference in most cases, but is there one format we should try to use everywhere? |
Since the parameters are an immutable series of items, tuples. |
I've created #6653 to use tuples more often (plus some other things I noticed). |
The accepted answer is much better than the one you are referring. Immutability is a property of tuples, but not a purpose. Tuples are intended to store heterogeneous data. When you have (x, y, z) or (Name, Age, Vocation) in your program, it doesn't make sense to add another name in the end or change the order. It just different types of data. On the other hand, lists are used for homogeneous data. It worth nothing to add a person to the list of the persons or swap two persons in the list: it will remain the list of persons. |
Currently many of the pytest tests start with a loop over a list of some values, with all of the test code inside this loop.
Pillow/Tests/test_image_paste.py
Lines 104 to 112 in 4dd678a
Instead, we can use pytest's
@pytest.mark.parametrize
annotation to handle this looping automatically.Pillow/Tests/test_image_paste.py
Lines 106 to 114 in b236c61
The benefit of using pytest to do this is that if a test fails, it tells you which parameter it failed with. Also pytest will test with each of the parameters instead of stopping on the first failure.
I've already made this change for one file (#6519), but there are a lot more tests that could benefit from this annotation.
The text was updated successfully, but these errors were encountered: