summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 18:55:21 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 18:55:21 +0200
commit51f37a8aab7a0d34231e945b9eeea12de5761fbb (patch)
tree776646d40896cd370493c9f9532b01adcf55fd8c
parent1eba9d0515e2528f504d0d7e277f6bf39cdc8e2e (diff)
downloadpsutil-51f37a8aab7a0d34231e945b9eeea12de5761fbb.tar.gz
register testfiles which are created during tests so that they can be cleanup up more easily
-rw-r--r--psutil/tests/__init__.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index d1f1fdef..2db667ed 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -27,6 +27,7 @@ import tempfile
import textwrap
import threading
import time
+import traceback
import warnings
from socket import AF_INET
from socket import AF_INET6
@@ -174,7 +175,7 @@ SOCK_SEQPACKET = getattr(socket, "SOCK_SEQPACKET", object())
_subprocesses_started = set()
_pids_started = set()
-_testfiles_created = set()
+_testfiles = set()
@atexit.register
@@ -182,12 +183,12 @@ def _cleanup_files():
DEVNULL.close()
for name in os.listdir(_HERE):
if name.startswith(TESTFILE_PREFIX):
- _testfiles_created.add(name)
- for name in _testfiles_created:
+ _testfiles.add(name)
+ for name in _testfiles:
try:
safe_rmpath(name)
- except UnicodeEncodeError as exc:
- warn(exc)
+ except Exception:
+ traceback.print_exc()
# this is executed first
@@ -284,6 +285,7 @@ def create_proc_children_pair():
The caller is supposed to clean them up with reap_children().
"""
_TESTFN2 = os.path.basename(_TESTFN) + '2' # need to be relative
+ _testfiles.add(_TESTFN2)
s = textwrap.dedent("""\
import subprocess, os, sys, time
PYTHON = os.path.realpath(sys.executable)
@@ -306,6 +308,7 @@ def create_proc_children_pair():
return (child1, child2)
except Exception:
reap_children()
+ safe_rmpath(_TESTFN2)
raise
@@ -317,7 +320,7 @@ def pyrun(src):
"""
with tempfile.NamedTemporaryFile(
prefix=TESTFILE_PREFIX, mode="wt", delete=False) as f:
- _testfiles_created.add(f.name)
+ _testfiles.add(f.name)
f.write(src)
f.flush()
subp = get_test_subprocess([PYTHON, f.name], stdout=None,
@@ -639,8 +642,9 @@ def create_exe(outpath, c_code=None):
def unique_filename(prefix=TESTFILE_PREFIX, suffix=""):
- return tempfile.mktemp(prefix=prefix, suffix=suffix)
-
+ ret = tempfile.mktemp(prefix=prefix, suffix=suffix)
+ _testfiles.add(ret)
+ return ret
# ===================================================================
# --- testing