Since Python 3.12 the standard library has included an `os.unshare` function. Use it if it is available. Signed-off-by: Jeremy Sowden --- 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