Skip to content

Commit c5c6238

Browse files
committed
pythongh-124213: Skip tests failing with --suppress-sync=true when inside systemd-nspawn container
Add a helper functon that checks whether the test suite is running inside a systemd-nspawn container, and skip the few tests failing with `--suppress-sync=true` in that case. The tests are failing because `--suppress-sync=true` stubs out `fsync()`, `fdatasync()` and `msync()` calls, and therefore they always return success without checking for invalid arguments. Technically, this means that the tests are also skipped when running inside systemd-nspawn container without `--suppress-sync=true`. However, to the best of my knowledge the only way to detect this option is to actually reproduce one of the unexpectedly-succeeding syscalls, and since this is precisely what we're testing for, the skip-test and the actual test would be doing the same thing. Signed-off-by: Michał Górny <[email protected]>
1 parent a9ffcd6 commit c5c6238

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

Lib/test/support/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import unittest
3737
import urllib.error
3838
import warnings
39+
from pathlib import Path
3940

4041
from .testresult import get_test_runner
4142

@@ -119,7 +120,8 @@
119120
"run_with_locale", "swap_item",
120121
"swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict",
121122
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count",
122-
"ALWAYS_EQ", "LARGEST", "SMALLEST"
123+
"ALWAYS_EQ", "LARGEST", "SMALLEST",
124+
"in_systemd_nspawn",
123125
]
124126

125127
class Error(Exception):
@@ -3411,3 +3413,11 @@ def adjust_int_max_str_digits(max_digits):
34113413
yield
34123414
finally:
34133415
sys.set_int_max_str_digits(current)
3416+
3417+
3418+
def in_systemd_nspawn() -> bool:
3419+
try:
3420+
return (Path("/run/systemd/container").read_bytes().rstrip() ==
3421+
b"systemd-nspawn")
3422+
except FileNotFoundError:
3423+
return False

Lib/test/test_mmap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from test.support import (TESTFN, import_module, unlink,
2-
requires, _2G, _4G, gc_collect, cpython_only)
2+
requires, _2G, _4G, gc_collect, cpython_only,
3+
in_systemd_nspawn,)
34
import unittest
45
import os
56
import re
@@ -740,7 +741,7 @@ def test_flush_return_value(self):
740741
mm.write(b'python')
741742
result = mm.flush()
742743
self.assertIsNone(result)
743-
if sys.platform.startswith('linux'):
744+
if sys.platform.startswith('linux') and not in_systemd_nspawn():
744745
# 'offset' must be a multiple of mmap.PAGESIZE on Linux.
745746
# See bpo-34754 for details.
746747
self.assertRaises(OSError, mm.flush, 1, len(b'python'))

Lib/test/test_os.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,8 +1852,12 @@ def test_chmod(self):
18521852

18531853

18541854
class TestInvalidFD(unittest.TestCase):
1855-
singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat",
1856-
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
1855+
singles = ["fchdir", "dup", "fdopen", "fstat",
1856+
"fstatvfs", "tcgetpgrp", "ttyname"]
1857+
# systemd-nspawn --suppress-sync=true does not verify fd passed
1858+
# fdatasync() and fsync(), and always returns success
1859+
if not support.in_systemd_nspawn():
1860+
singles += ["fdatasync", "fsync"]
18571861
#singles.append("close")
18581862
#We omit close because it doesn't raise an exception on some platforms
18591863
def get_single(f):

0 commit comments

Comments
 (0)