summaryrefslogtreecommitdiffstats
path: root/test/framework.py
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2017-04-11 06:01:53 +0200
committerDamjan Marion <dmarion.lists@gmail.com>2017-04-12 17:12:58 +0000
commit027dbd528827c8cce6d07cf806694d2b0d53498e (patch)
tree7615744d563f901b1b4792f2d39d87d102eb210d /test/framework.py
parent6a0946f078183361a5b757f6405165089b659c5c (diff)
make test: don't rely on cPython GC to close fds
This code improvement allows running in pypy (and other interpreters) without exhausting file descriptors. Change-Id: Icb692a0fe1343c12cbbb15af6c58753420e74330 Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'test/framework.py')
-rw-r--r--test/framework.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/test/framework.py b/test/framework.py
index fc263e703eb..f105950ad5a 100644
--- a/test/framework.py
+++ b/test/framework.py
@@ -238,12 +238,12 @@ class VppTestCase(unittest.TestCase):
cls.logger = getLogger(cls.__name__)
cls.tempdir = tempfile.mkdtemp(
prefix='vpp-unittest-' + cls.__name__ + '-')
- file_handler = FileHandler("%s/log.txt" % cls.tempdir)
- file_handler.setFormatter(
+ cls.file_handler = FileHandler("%s/log.txt" % cls.tempdir)
+ cls.file_handler.setFormatter(
Formatter(fmt='%(asctime)s,%(msecs)03d %(message)s',
datefmt="%H:%M:%S"))
- file_handler.setLevel(DEBUG)
- cls.logger.addHandler(file_handler)
+ cls.file_handler.setLevel(DEBUG)
+ cls.logger.addHandler(cls.file_handler)
cls.shm_prefix = cls.tempdir.split("/")[-1]
os.chdir(cls.tempdir)
cls.logger.info("Temporary dir is %s, shm prefix is %s",
@@ -344,9 +344,9 @@ class VppTestCase(unittest.TestCase):
stdout_log(single_line_delim)
stdout_log('VPP output to stdout while running %s:', cls.__name__)
stdout_log(single_line_delim)
- f = open(cls.tempdir + '/vpp_stdout.txt', 'w')
vpp_output = "".join(cls.vpp_stdout_deque)
- f.write(vpp_output)
+ with open(cls.tempdir + '/vpp_stdout.txt', 'w') as f:
+ f.write(vpp_output)
stdout_log('\n%s', vpp_output)
stdout_log(single_line_delim)
@@ -354,9 +354,9 @@ class VppTestCase(unittest.TestCase):
stderr_log(single_line_delim)
stderr_log('VPP output to stderr while running %s:', cls.__name__)
stderr_log(single_line_delim)
- f = open(cls.tempdir + '/vpp_stderr.txt', 'w')
vpp_output = "".join(cls.vpp_stderr_deque)
- f.write(vpp_output)
+ with open(cls.tempdir + '/vpp_stderr.txt', 'w') as f:
+ f.write(vpp_output)
stderr_log('\n%s', vpp_output)
stderr_log(single_line_delim)
@@ -364,6 +364,7 @@ class VppTestCase(unittest.TestCase):
def tearDownClass(cls):
""" Perform final cleanup after running all tests in this test-case """
cls.quit()
+ cls.file_handler.close()
def tearDown(self):
""" Show various debug prints after each test """