Repository navigation
Conversation
|
Hi @phr4nky! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Summary: The default test main writes each test's status to the `-o` JSON from the last `_setStatus` call. A test whose subtest fails and whose later subtest is skipped was written as SUCCESS: the subtest branch of `addSkip` (added in 9218a1b) sets PASSED over the FAILURE that `addSubTest` recorded, and clears the stacktrace. A failed subtest followed by `self.skipTest()` was written as ASSUMPTION_VIOLATION the same way. unittest counts the failure in both cases and the run exits 70, so the per-test result disagrees with the run. A skip no longer replaces a failure or error recorded earlier in the same test; its message is still appended. Test Plan: Two new cases in `tests/test_main_test.py`. Both fail on the parent commit (SUCCESS and ASSUMPTION_VIOLATION instead of FAILURE) and pass with this change; the rest of the module passes.
e293bb5 to
5506e5f
Compare
|
This pull request has been imported. If you are a Meta employee, you can view this in D134594404. (Because this pull request was imported automatically, there will not be any future comments.) |
|
This pull request has been merged in 580490d. |
Summary:
The default `python_test` main, `prelude/python/tools/__test_main__.py`, writes a test as `SUCCESS` in its `-o` results when one subtest fails and a later subtest is skipped. This is the usual pattern of a parametrized test that skips unsupported platforms inside `subTest`. The run itself exits 70, so the per-test result contradicts it. A failed subtest followed by `self.skipTest()` is written as `ASSUMPTION_VIOLATION` in the same way.
## Affected version
Checked on `main` at 4b47e1430e and on the release `2026-11-15` (5b3b13d3ea); `__test_main__.py` is identical in both. The subtest-skip case came with 9218a1bc9c ("python: Report subtest skips and failures in the default test main"); the main from before that commit reports the same test as `FAILURE`.
## Reproduction
Put `prelude/python/tools/__test_main__.py` in an empty directory next to this test module and run it the way `python_test` does:
```python
# t_sub.py
import unittest
class T(unittest.TestCase):
def test_platforms(self):
for platform in ["linux", "windows"]:
with self.subTest(platform=platform):
if platform == "windows":
self.skipTest("windows not supported")
self.assertEqual(platform, "macos")
```
```
echo 'TEST_MODULES = ["t_sub"]' > __test_modules__.py
python3 __test_main__.py --hide-output -o out.json; echo "exit=$?"
python3 -c "import json; [print(r['testCase'], r['type']) for r in json.load(open('out.json')) if 'testCase' in r]"
```
## Expected
`test_platforms FAILURE`: unittest counts the failed subtest (`wasSuccessful()` is false, exit 70), and the main from before 9218a1bc9c reports `FAILURE`.
## Actual
```
exit=70
test_platforms SUCCESS
```
## Analysis
`_setStatus` overwrites `_current_status` and `_stacktrace` on every call. `addSubTest` records `FAILED` for the failing subtest; the subtest branch of `addSkip` then sets `PASSED` and clears the stacktrace. unittest calls no further result method for the test, so `PASSED` is what `stopTest` writes. A plain `addSkip` after a failed subtest sets `SKIPPED` the same way.
## Patch
A skip no longer replaces a failure or error already recorded for the same test; its message is still appended.
X-link: meta/buck2#1658
Reviewed By: dtolnay
Differential Revision: D134594404
fbshipit-source-id: 7d400704f5f578ca0d957e54ef0d4027503de2bf
Summary
The default
python_testmain,prelude/python/tools/__test_main__.py, writes a test asSUCCESSin its-oresults when one subtest fails and a later subtest is skipped. This is the usual pattern of a parametrized test that skips unsupported platforms insidesubTest. The run itself exits 70, so the per-test result contradicts it. A failed subtest followed byself.skipTest()is written asASSUMPTION_VIOLATIONin the same way.Affected version
Checked on
mainat 4b47e14 and on the release2026-11-15(5b3b13d);__test_main__.pyis identical in both. The subtest-skip case came with 9218a1b ("python: Report subtest skips and failures in the default test main"); the main from before that commit reports the same test asFAILURE.Reproduction
Put
prelude/python/tools/__test_main__.pyin an empty directory next to this test module and run it the waypython_testdoes:Expected
test_platforms FAILURE: unittest counts the failed subtest (wasSuccessful()is false, exit 70), and the main from before 9218a1b reportsFAILURE.Actual
Analysis
_setStatusoverwrites_current_statusand_stacktraceon every call.addSubTestrecordsFAILEDfor the failing subtest; the subtest branch ofaddSkipthen setsPASSEDand clears the stacktrace. unittest calls no further result method for the test, soPASSEDis whatstopTestwrites. A plainaddSkipafter a failed subtest setsSKIPPEDthe same way.Patch
A skip no longer replaces a failure or error already recorded for the same test; its message is still appended.
Test Plan: two new cases in
prelude/python/tools/tests/test_main_test.py(a later skipped subtest;skipTestafter a failed subtest). Both fail on the parent commit (SUCCESSandASSUMPTION_VIOLATIONinstead ofFAILURE) and pass with the change; the rest of the module passes. The reproduction above printstest_platforms FAILUREwith the change.