Skip to content

Commit 2489dee

Browse files
committed
Add root user checks to test.support
This partially backports commit 86b8617 (GH-146195); making existing tests use the helper is omitted.
1 parent 22554ca commit 2489dee

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎Lib/test/support/__init__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,3 +2598,8 @@ def control_characters_c0() -> list[str]:
25982598
C0 control characters defined as the byte range 0x00-0x1F, and 0x7F.
25992599
"""
26002600
return [chr(c) for c in range(0x00, 0x20)] + ["\x7F"]
2601+
2602+
2603+
_ROOT_IN_POSIX = hasattr(os, 'geteuid') and os.geteuid() == 0
2604+
requires_root_user = unittest.skipUnless(_ROOT_IN_POSIX, "test needs root privilege")
2605+
requires_non_root_user = unittest.skipIf(_ROOT_IN_POSIX, "test needs non-root account")

0 commit comments

Comments
 (0)