Open saroad2 opened 2 years ago
@JelleZijlstra , @ichard26 , @cooperlees , would love to hear your opinion on this so I could start implement it.
This is a direct continuation of all the other stuff we did regarding unit testing
Howdy - This sounds great to me and I have no objections to lots of smaller modules and test data since the overhead of adding it to the all_data_cases allows easier scaling etc.
I'm happy to review and help get these improvements merged. I just ask lets do lots of smaller PRs moving there and I'll try do faster reviews so you don't get blocked :)
Honestly I don't see a big problem with the current size of the data files. Having too many small files makes it harder to navigate.
The size is less of a bother to me too, but I do dislike the fact that expected output can be a long scroll from the input. Another option to fix that could be to change the file format to allow multiple test blocks.
Hey @JelleZijlstra , thanks for the honest opinion.
There are a few reasons why we would want smaller test cases. Take a look at long_strings.py test case. It has 661 lines and total of 67 statements. When we test those statements as part of test_preview_format we are actually running 67 individual tests all at once, one for each formatted statement.
This is fine when all tests are passing, but it can be hell when this test is failing: the error prints are humongous, long and confusing, and trying to search for a single error in a test file of 661 lines is unnecessary at best.
If we manage to split this case to 67 smaller cases, one for each statement, we get a few advantages:
I hope this convinces you that splitting the test cases is the right move. If you have any caviets, I would love to hear them.
Why would we need to read through the whole file? That sounds like it can be solved by making the test machinery output better line numbers.
I tried making a small change that breaks tests (formatting 1e6
as 1e+6
). Here's the output I got:
To fix the test I need two things: the data filename and the approximate line where it's failing. The first is pretty easy, because we give a diff with line numbers, but the filename is harder to find because we print so much junk before it.
Here's some concrete things that would help me fix this test failure faster:
_assert_format_equal
.True, having better test output would be half the battle. Maybe we could make a Pytest argument for those that want to see verbose test output like so (no experience with it though).
The other half is writing tests. It's inconvenient to scroll around the file needlessly, although in fairness it has worked well so far! So.. the inconvenience of scrolling vs. the inconvenience of making a large set of changes and having more files or more test blocks.. Honestly I'm not sure 🤷♂️
In my humble opinion, keeping these long case files is a mistake, from all the reasons I mentioned above.
In the end, it's up to you. If you choose to split the cases, I would do that happily.
Description We've made a lot of progress improving the testing process in #3034 and #3062.
A problem that still remains is that the existing cases data files are ENORMOUS. those data files can contain up to 300 lines (and even more), which is way too much for a test. Cases files, and tests in general, should be short and concise in order for us to track down errors as easy as possible.
I would like to suggest scanning all of our cases data files and split them into small cases, each case testing only one behavior. In that way when encountering a failed test, we'll see exactly which test has failed and on which line it failed without searching over hundreds of lines of code.
Why now?
Up until now, every case data file had to be added manually to a list of cases. This is no longer the case after #3062. Now, whenever you add a test to a directory it will be added automatically to the relevant cases list.
Now we can afford having as many cases data files as we want without writing all of these tests to huge, hard-coded lists. All of our data files will be read automatically and will be processed automatically according to the directory that they're in.
How can we do it?
Very simple:
all_data_cases
function to search cases also in subdirectories of the given directory.If we keep each case in its right directory, all of the tests should keep passing without changing them.
Additional context
This is a continuation of a discussion over at #3035 of @felix-hilden and me.