bearomorphism opened a new pull request, #59371:
URL: https://github.com/apache/spark/pull/59371

   ### What changes were proposed in this pull request?
   
   Extend the existing `UtilTests.test_disable_gc` test in place to cover:
   
   - Initially enabled and already-disabled GC.
   - Nested contexts, checking that the inner exit does not re-enable GC.
   - Exception cleanup, checking that the original GC state is restored.
   
   Register cleanup to restore the caller's GC state even if an assertion 
fails. No new test class or production changes.
   
   ### Why are the changes needed?
   
   The existing test covers only a normal exit with GC initially enabled. It 
does not cover the already-disabled branches or protect nested contexts and 
exception cleanup against regressions.
   
   In isolated runs of this helper, the previous happy-path assertions cover 2 
of 4 branch outcomes; the expanded test covers all 4. Line coverage is 
unchanged. These are helper-level measurements, not repository-wide coverage 
numbers.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   The expanded test body passed with the caller's GC initially enabled and 
disabled, using `unittest.FunctionTestCase` to exercise the assertions, 
subtests, and cleanup without starting the existing Spark fixture:
   
   ```bash
   source .venv/bin/activate
   PYTHONPATH=python SPARK_HOME="$PWD" python - <<'PY'
   import gc
   import unittest
   from pyspark.tests.test_util import UtilTests
   
   originally_enabled = gc.isenabled()
   try:
       for enabled, set_gc in ((True, gc.enable), (False, gc.disable)):
           set_gc()
           case = unittest.FunctionTestCase(lambda: 
UtilTests.test_disable_gc(case))
           result = unittest.TextTestRunner(verbosity=2).run(case)
           assert result.wasSuccessful()
           assert gc.isenabled() == enabled
   finally:
       (gc.enable if originally_enabled else gc.disable)()
   PY
   ruff check python/pyspark/tests/test_util.py
   ruff format --check python/pyspark/tests/test_util.py
   git diff --check
   ```
   
   All checks passed. A branch-coverage run of the test body confirmed all four 
branch outcomes in `disable_gc` are exercised. The full Spark-backed 
`UtilTests` fixture was not run locally because this checkout does not have a 
built Spark assembly.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: pi 1.1.0
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to