jh1231223 opened a new pull request, #36485:
URL: https://github.com/apache/beam/pull/36485
Thanks for reviewing!
**Context / Issue**
- Addresses flaky behavior tracked in #35211.
- In `PortableRunnerTest::test_assert_that`, a failing `assert_that` raised
on a worker thread was only surfaced as a
`PytestUnhandledThreadExceptionWarning`, so the test could pass intermittently.
**What this change does**
- Captures `threading.excepthook` during the test run.
- Wraps `beam.Pipeline.run(...).wait_until_finish()` so that any captured
worker-thread exception is rethrown on the main thread at the end of the run.
- Updates `test_assert_that` to use this shim and assert the expected
failure via `assertRaisesRegex`, turning the flaky pass into a deterministic
failure for the negative case.
**Why**
Ensures the failure path for `assert_that` is exercised reliably and
reported as a proper test failure, rather than a warning emitted from a
background thread.
**Summary**
The failure originally occurred on a worker thread rather than the main
thread, causing pytest to emit a PytestUnhandledThreadExceptionWarning instead
of failing the test. This fix intercepts those background-thread exceptions via
threading.excepthook and re-throws them on the main thread after
wait_until_finish(), so pytest now treats them as proper test failures. The
warning no longer appears because the exception is no longer “unhandled,”
eliminating the nondeterministic pass/fail behavior.
**Verification**
Stress run x200 (no flakes):
```
for i in {1..200}; do
echo "Run $i"
pytest -q
apache_beam/runners/portability/portable_runner_test.py::PortableRunnerTest::test_assert_that
\
-W error::pytest.PytestUnhandledThreadExceptionWarning -s --maxfail=1 ||
break
done
```
Result: `200/200` passes; no thread-exception warnings.
--
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]