aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2024-10-02 14:58:25 +0200
committerMichał Górny <mgorny@gentoo.org>2024-10-07 19:37:13 +0200
commit5b2c6530598636afd2c5f28aac8264982a6d807e (patch)
tree27ceb400f33735a1d97d93f5102f7c279b3d4939
parentgh-124213: Skip tests failing inside systemd-nspawn --suppress-sync=true (#12... (diff)
downloadcpython-5b2c6530598636afd2c5f28aac8264982a6d807e.tar.gz
cpython-5b2c6530598636afd2c5f28aac8264982a6d807e.tar.bz2
cpython-5b2c6530598636afd2c5f28aac8264982a6d807e.zip
gh-124213: Fix incorrect context manager use in in_systemd_nspawn_sync_suppressed()gentoo-3.13.0
Fix the incorrect use of `os.open()` result as a context manager, while it is actually a numeric file descriptor. I have missed the problem, because in the original version the `os.open()` call would always fail, and I failed to test the final version in all possible scenarios properly. Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r--Lib/test/support/__init__.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 184a1783855..306a6ce262a 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2725,10 +2725,11 @@ def in_systemd_nspawn_sync_suppressed() -> bool:
# trigger EINVAL. Otherwise, ENOENT will be given instead.
import errno
try:
- with os.open(__file__, os.O_RDONLY | os.O_SYNC):
- pass
+ fd = os.open(__file__, os.O_RDONLY | os.O_SYNC)
except OSError as err:
if err.errno == errno.EINVAL:
return True
+ else:
+ os.close(fd)
return False