Add wrapper around pytest's '-x' flag to |mach python-test|
Categories
(Testing :: Python Test, enhancement)
Tracking
(firefox71 fixed)
Tracking | Status | |
---|---|---|
firefox71 | --- | fixed |
People
(Reporter: ahal, Assigned: anmol.agarwal001, Mentored)
Details
Attachments
(1 file)
Comment 1•6 years ago
|
||
Reporter | ||
Comment 2•6 years ago
|
||
Comment 3•6 years ago
|
||
Reporter | ||
Updated•6 years ago
|
Assignee | ||
Comment 4•5 years ago
|
||
Hey ahal,
As far as I have understood by reading the bug summary and some of the code in python/mach_commands.py, what I got is that there are some tests which are run in parallel (concurrently) and some sequentially. Now the requirement is to add an option -x, which will stop the test as soon as there is a failure. I have got confusion among the following two:
- Here the first failure is considered as a test object/file. If yes, then let's say there are 5 sequential test objects/files and the first failure is at object 3, then other 2 won't be processed. But, then how will this be handled for parallel running tests?
- Here the first failure is considered as a test function inside a test object/file. If yes, then as per the above example all 5 test objects will be processed. But, if there are 6 test functions in test object 1 and test function 2 fails, then the remaining 4 shouldn't be processed.
Please clarify.
Reporter | ||
Comment 5•5 years ago
|
||
It's the second one, a failure is a test function within a test file. Getting this part working is easy, we just need to forward -x
to the pytest command line:
https://searchfox.org/mozilla-central/source/config/mozunit/mozunit/mozunit.py#248
Maybe we can even just set the PYTEST_ADDOPTS
environment variable.
The tricky bit is going to be how do we stop all of the other threads when one of the files fails. There are two possibilities here:
- If passing -x, just run all tests in sequence.
- If a test file returns non-zero, then we raise and catch an exception and then try and stop the threads like this:
https://searchfox.org/mozilla-central/source/python/mach_commands.py#181
I'd vote we at least attempt #2 and see if it'll work. If not we can just do the sequential thing.
Assignee | ||
Comment 6•5 years ago
|
||
Hey ahal,
If it's the second one, then why do we need to stop the other threads if one of it fails. What I understand is, let's say there are 3 sequential jobs (Job id 1-3) and 3 parallel jobs (Job id 4-6). Here I am considering that one job is associated to one test file as per your first comment.
Sequential Jobs:
- Job 1 has 5 cases and all of them were a success
- Job 2 has 4 cases and failed at case 2
- Job 3 has 5 cases and failed at case 3
Parallel Jobs:
- Job 4 has 5 cases and failed at case 2
- Job 5 has 4 cases and all were success
- Job 6 has 4 cases and failed at case 3
Then according to me, the output will be something like (if we pass -x option):
Job 1: All passed cases
Job 2: Case 1 passed, Case 2 failed and Case 3, 4 skipped
Job 3: Case 1, 2 passed, Case 3 failed and Case 4, 5 skipped
Job 4: Case 1 passed, Case 2 failed and Case 3, 4, 5 skipped
Job 5: All cases passed
Job 6: Case 1, 2 passed, Case 3 failed and Case 4 skipped
The difference would be that Jobs 1, 2 and 3 would have generated their outputs by running sequentially. Jobs 4, 5, 6 would have generated their outputs by running in parallel.
Please correct if I am wrong. Can you please use the same example to explain if wrong.
Reporter | ||
Comment 7•5 years ago
|
||
The purpose of -x
is to debug test failures rapidly, e.g maybe there are multiple failures and you want to focus on one at a time. So you pass -x
and your run exits as soon as it hits a failure. This A) ensures the failure is at the bottom of your terminal, and B) means you don't need to wait for the rest of your tests to finish.
However, typing this out I realized something. If we continue to run tests in parallel then the order of execution of tests isn't guaranteed. This is undesirable because it makes debugging a specific failure difficult. So I've changed my mind and think we should go with option 1. When passing in -x, all tests should be run in sequence.
Assignee | ||
Comment 8•5 years ago
|
||
Hey ahal,
I just raised a revison review request. Please see if it meets the requirements https://phabricator.services.mozilla.com/D47321
Assignee | ||
Comment 9•5 years ago
|
||
Bug 1494090 - Added -x option to |mach python-test|
Comment 10•5 years ago
|
||
Assignee | ||
Comment 11•5 years ago
|
||
Hey ahal,
Please assign this bug to me. Moreover, as per your comments on the revision, it looks this this has been resolved. If yes, please change the status too.
Comment 12•5 years ago
|
||
bugherder |
Updated•5 years ago
|
Description
•