Skip to content

gh-152548: Convert the test_signal wakeup tests to @isolated()#152639

Open
serhiy-storchaka wants to merge 5 commits into
python:mainfrom
serhiy-storchaka:test-signal-isolated
Open

gh-152548: Convert the test_signal wakeup tests to @isolated()#152639
serhiy-storchaka wants to merge 5 commits into
python:mainfrom
serhiy-storchaka:test-signal-isolated

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

The wakeup tests in WakeupSignalTests and WakeupSocketSignalTests need a process with no background thread so that signals are delivered to the main thread. Each was driven as a hand-written script string run in a child process via assert_python_ok('-c', ...), signalling failures with bare raise and reported to the runner only through the child exit code.

With @isolation.isolated() the same code runs as a normal method body in a fresh subprocess, using self.assert* and reported per test, with the subprocess traceback shown as the cause of a failure. The check_wakeup() helper becomes an ordinary helper that runs a test(read) callback in-process and asserts the read-back; the _testcapi skips move to the parent process (so no subprocess is spawned when skipped).

This is built on top of #152551 (the test.support.isolation submodule). The first four commits belong to that PR and will drop out once it is merged and this branch is rebased.

serhiy-storchaka and others added 5 commits June 29, 2026 10:26
Run a test in a fresh interpreter subprocess, so that it does not share global
or interpreter state with the rest of the test run.  It can decorate a test
method (only that method runs in a subprocess) or a TestCase subclass (the
whole class runs in one subprocess, with its setUpClass()/setUp()/tearDown()/
tearDownClass() running once there).

Failures, errors and skips, including those of individual subtests, are
reported for the test and show the original subprocess traceback.  The
subprocess inherits the parent's resource, memory and verbosity configuration,
so that requires_resource(), bigmemtest() and similar behave the same in both
processes.

The test.support.running_isolated flag is true in the subprocess, so that
fixtures can choose what to run there.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Fixes the ruff F401 "imported but unused" lint failure for the re-exports.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@isolated() always runs the test in a subprocess, so skip it in the
parent process on platforms that lack subprocess support, the same way
the tests it replaces were guarded by requires_subprocess().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the helper into a public test.support.isolation submodule (used as
"from test.support import isolation"), drop the test.support re-export,
and document running_isolated and isolated() under that module.

Replay expected failures and forward subprocess durations to the parent,
so an @expectedfailure isolated test is no longer misreported as an
unexpected success and reported timings reflect the subprocess run.

Add test.test_support.TestIsolated covering the outcomes, subtest
reporting, traceback-as-cause, duration forwarding and the no-subprocess
skip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
WakeupSignalTests and WakeupSocketSignalTests ran each test as a script
string via assert_python_ok('-c', ...), using a subprocess to have a
single thread for signal delivery. Decorate them with @isolated()
instead, so the same code runs as a normal method body using self.assert*.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33364015 | 📁 Comparing cb4fa6a against main (edcc07d)

  🔍 Preview build  

2 files changed
± library/test.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant