Skip to content

Commit 7c4a8e5

Browse files
miss-islingtonfreakboy3742hugovk
authored
[3.14] pythongh-140702: Add test skip for Unix Datagram tests on iOS when on Github Actions (pythonGH-140740) (python#140742)
Exposes the GITHUB_ACTIONS environment variable to iOS simulator test runs, and uses this variable to skip a Unix Datagram socketserver test that is unreliable in the iOS GitHub Actions environment. (cherry picked from commit 9f8d005) Co-authored-by: Russell Keith-Magee <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 8f322ad commit 7c4a8e5

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

Apple/iOS/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ Once you have a built an XCframework, you can test that framework by running:
224224

225225
$ python Apple test iOS
226226

227+
This test will attempt to find an "SE-class" simulator (i.e., an iPhone SE, or
228+
iPhone 16e, or similar), and run the test suite on the most recent version of
229+
iOS that is available. You can specify a simulator using the `--simulator`
230+
command line argument, providing the name of the simulator (e.g., `--simulator
231+
'iPhone 16 Pro'`). You can also use this argument to control the OS version used
232+
for testing; `--simulator 'iPhone 16 Pro,OS=18.2'` would attempt to run the
233+
tests on an iPhone 16 Pro running iOS 18.2.
234+
235+
If the test runner is executed on GitHub Actions, the `GITHUB_ACTIONS`
236+
environment variable will be exposed to the iOS process at runtime.
237+
227238
### Testing a single-architecture framework
228239

229240
The `Apple/testbed` folder that contains an Xcode project that is able to run

Apple/testbed/TestbedTests/TestbedTests.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ - (void)testPython {
3535
setenv("NO_COLOR", "1", true);
3636
setenv("PYTHON_COLORS", "0", true);
3737

38+
if (getenv("GITHUB_ACTIONS")) {
39+
NSLog(@"Running in a GitHub Actions environment");
40+
}
3841
// Arguments to pass into the test suite runner.
3942
// argv[0] must identify the process; any subsequent arg
4043
// will be handled as if it were an argument to `python -m test`

Apple/testbed/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import json
3+
import os
34
import re
45
import shutil
56
import subprocess
@@ -78,13 +79,21 @@ def xcode_test(location: Path, platform: str, simulator: str, verbose: bool):
7879
check=True,
7980
)
8081

82+
# Any environment variable prefixed with TEST_RUNNER_ is exposed into the
83+
# test runner environment. There are some variables (like those identifying
84+
# CI platforms) that can be useful to have access to.
85+
test_env = os.environ.copy()
86+
if "GITHUB_ACTIONS" in os.environ:
87+
test_env["TEST_RUNNER_GITHUB_ACTIONS"] = os.environ["GITHUB_ACTIONS"]
88+
8189
print("Running test project...")
8290
# Test execution *can't* be run -quiet; verbose mode
8391
# is how we see the output of the test output.
8492
process = subprocess.Popen(
8593
["xcodebuild", "test-without-building"] + args,
8694
stdout=subprocess.PIPE,
8795
stderr=subprocess.STDOUT,
96+
env=test_env,
8897
)
8998
while line := (process.stdout.readline()).decode(*DECODE_ARGS):
9099
# Strip the timestamp/process prefix from each log line

Lib/test/support/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"BrokenIter",
6969
"in_systemd_nspawn_sync_suppressed",
7070
"run_no_yield_async_fn", "run_yielding_async_fn", "async_yield",
71-
"reset_code",
71+
"reset_code", "on_github_actions"
7272
]
7373

7474

@@ -1370,6 +1370,7 @@ def reset_code(f: types.FunctionType) -> types.FunctionType:
13701370
f.__code__ = f.__code__.replace()
13711371
return f
13721372

1373+
on_github_actions = "GITHUB_ACTIONS" in os.environ
13731374

13741375
#=======================================================================
13751376
# Check for the presence of docstrings.

Lib/test/test_socketserver.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,16 @@ def test_ForkingUDPServer(self):
218218
self.dgram_examine)
219219

220220
@requires_unix_sockets
221+
@unittest.skipIf(test.support.is_apple_mobile and test.support.on_github_actions,
222+
"gh-140702: Test fails regularly on iOS simulator on GitHub Actions")
221223
def test_UnixDatagramServer(self):
222224
self.run_server(socketserver.UnixDatagramServer,
223225
socketserver.DatagramRequestHandler,
224226
self.dgram_examine)
225227

226228
@requires_unix_sockets
229+
@unittest.skipIf(test.support.is_apple_mobile and test.support.on_github_actions,
230+
"gh-140702: Test fails regularly on iOS simulator on GitHub Actions")
227231
def test_ThreadingUnixDatagramServer(self):
228232
self.run_server(socketserver.ThreadingUnixDatagramServer,
229233
socketserver.DatagramRequestHandler,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The iOS testbed app will now expose the ``GITHUB_ACTIONS`` environment
2+
variable to iOS apps being tested.

0 commit comments

Comments
 (0)