Skip to contentSkip to conversation

tests: py: use tempfile module

PATCH In review Eric Garver 1 participant 2 messages Jun 19, 2019 – Jun 27, 2019 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests: py: use tempfile module

os.tmpfile() is not in python3.

---
 tests/py/nft-test.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tests/py/nft-test.py +3 -2
index f80517e67bfd..4da6fa650f6d 100755
@@ -20,6 +20,7 @@ import argparse
 import signal
 import json
 import traceback
+import tempfile
 
 TESTS_PATH = os.path.dirname(os.path.abspath(__file__))
 sys.path.insert(0, os.path.join(TESTS_PATH, '../../py/'))
@@ -771,7 +772,7 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path):
             unit_tests += 1
             table_flush(table, filename, lineno)
 
-            payload_log = os.tmpfile()
+            payload_log = tempfile.TemporaryFile(mode="w+")
 
             # Add rule and check return code
             cmd = "add rule %s %s %s" % (table, chain, rule[0])
@@ -911,7 +912,7 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path):
                               gotf.name, 1)
 
             table_flush(table, filename, lineno)
-            payload_log = os.tmpfile()
+            payload_log = tempfile.TemporaryFile(mode="w+")
 
             # Add rule in JSON format
             cmd = json.dumps({ "nftables": [{ "add": { "rule": {
Signature · 1 line
2.20.1
#1 lore raw
Quoted 4 lines · Eric Garver

os.tmpfile() is not in python3.

---

Pablo,

Shekhar included this change in patch "[PATCH nft v9]tests: py: fix pyhton3". So this patch can be dropped.

Thanks.
Eric.