Skip to content

Commit a3d96cf

Browse files
committed
Add a test of stdlib availability during .pth handling.
1 parent d18d4c0 commit a3d96cf

5 files changed

Lines changed: 31 additions & 1 deletion

File tree

pth-tester/pth_tester.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
initialized = False
2+
has_socket = False
23

34

45
# The pth_tester module should be initalized by processing the `.pth` file
56
# created on installation.
67
def init():
78
global initialized
9+
global has_socket
10+
811
initialized = True
12+
13+
# At the time that the module is initialized, it *should* have access
14+
# to all of the standard library. This might not be true, depending on
15+
# the initialization order of the site module and sys.path.
16+
try:
17+
import socket # NOQA: F401
18+
19+
has_socket = True
20+
except ImportError:
21+
pass

pth-tester/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "x-pth-tester"
7-
version = "1.0.0"
7+
version = "2025.3.26"
88
classifiers = ["Private :: Do Not Upload"]

tests/test_common.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,20 @@ def test_pth_handling():
453453
# The pth_tester module should be "initialized" as a result of
454454
# processing the .pth file created when the package is installed.
455455
assert pth_tester.initialized
456+
457+
# When the .pth file is processed, the full standard library should be
458+
# available. Check if the initialization process could import socket.
459+
if sys.platform == "android" or hasattr(sys, "getandroidapilevel"):
460+
# Android is known to have an issue with .pth/sys.path ordering that
461+
# causes this test to fail. For now, accept this as an XFAIL; if it
462+
# passes, fail as an indicator that the bug has been resolved, and we
463+
# can simplify the test.
464+
try:
465+
assert pth_tester.has_socket
466+
pytest.fail("Android .pth handling bug has been resolved.")
467+
except AssertionError:
468+
pytest.xfail(
469+
"On Android, .pth files are processed before sys.path is finalized."
470+
)
471+
else:
472+
assert pth_tester.has_socket
-1.44 KB
Binary file not shown.
1.64 KB
Binary file not shown.

0 commit comments

Comments
 (0)