All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft] tests: py: use `os.unshare` Python function
@ 2026-03-05 17:53 Jeremy Sowden
  2026-03-05 22:15 ` Phil Sutter
  2026-03-06 17:41 ` Phil Sutter
  0 siblings, 2 replies; 9+ messages in thread
From: Jeremy Sowden @ 2026-03-05 17:53 UTC (permalink / raw)
  To: Netfilter Devel

Since Python 3.12 the standard library has included an `os.unshare` function.
Use it if it is available.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 tests/py/nft-test.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index 53fd3f7ae6fe..64837da36035 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -1466,7 +1466,14 @@ def run_test_file(filename, force_all_family_option, specific_file):
     return [tests, passed, total_warning, total_error, total_unit_run]
 
 def spawn_netns():
-    # prefer unshare module
+    # prefer stdlib unshare function ...
+    try:
+        os.unshare(os.CLONE_NEWNET)
+        return True
+    except Exception as e:
+        pass
+
+    # ... or unshare module
     try:
         import unshare
         unshare.unshare(unshare.CLONE_NEWNET)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-13  7:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 17:53 [PATCH nft] tests: py: use `os.unshare` Python function Jeremy Sowden
2026-03-05 22:15 ` Phil Sutter
2026-03-06 17:41 ` Phil Sutter
2026-03-06 18:35   ` Jeremy Sowden
2026-03-10 23:08     ` Phil Sutter
2026-03-12 22:14       ` Florian Westphal
2026-03-12 22:20         ` Pablo Neira Ayuso
2026-03-13  7:57           ` Jeremy Sowden
2026-03-13  7:56       ` Jeremy Sowden

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.