Skip to content

Commit 1b4c903

Browse files
miss-islingtonfreakboy3742hugovk
committed
[3.10] 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 <russell@keith-magee.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 9ac1b47 commit 1b4c903

6 files changed

Lines changed: 33 additions & 0 deletions

File tree

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
@@ -79,13 +80,21 @@ def xcode_test(location: Path, platform: str, simulator: str, verbose: bool):
7980
check=True,
8081
)
8182

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

Lib/test/support/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"run_with_tz", "PGO", "missing_compiler_executable",
5656
"ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST",
5757
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
58+
"on_github_actions"
5859
]
5960

6061

@@ -1049,6 +1050,9 @@ def refcount_test(test):
10491050
return no_tracing(cpython_only(test))
10501051

10511052

1053+
on_github_actions = "GITHUB_ACTIONS" in os.environ
1054+
1055+
10521056
def _filter_suite(suite, pred):
10531057
"""Recursively filter test cases in a suite based on a predicate."""
10541058
newtests = []

Lib/test/test_socketserver.py

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

234234
@requires_unix_sockets
235+
@unittest.skipIf(test.support.is_apple_mobile and test.support.on_github_actions,
236+
"gh-140702: Test fails regularly on iOS simulator on GitHub Actions")
235237
def test_UnixDatagramServer(self):
236238
self.run_server(socketserver.UnixDatagramServer,
237239
socketserver.DatagramRequestHandler,
238240
self.dgram_examine)
239241

240242
@requires_unix_sockets
243+
@unittest.skipIf(test.support.is_apple_mobile and test.support.on_github_actions,
244+
"gh-140702: Test fails regularly on iOS simulator on GitHub Actions")
241245
def test_ThreadingUnixDatagramServer(self):
242246
self.run_server(socketserver.ThreadingUnixDatagramServer,
243247
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)