summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 08:49:00 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 08:49:00 +0200
commit275dc089ab04cb86647eb56d405384bc00ebea86 (patch)
tree013dd779657c4a7d1a3d5fc28bc017ff4d07d5fe
parenta40c3187a491d22826a1cbcf576f94e00c9a7cc2 (diff)
downloadpsutil-275dc089ab04cb86647eb56d405384bc00ebea86.tar.gz
clever atexit logic
-rw-r--r--psutil/tests/__init__.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index 771a3cc3..f1e0903e 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -145,6 +145,7 @@ ASCII_FS = sys.getfilesystemencoding().lower() in ('ascii', 'us-ascii')
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts')
+_HERE = os.path.abspath(os.path.dirname(__file__))
# --- support
@@ -176,6 +177,19 @@ _pids_started = set()
_testfiles_created = set()
+@atexit.register
+def _cleanup():
+ DEVNULL.close()
+ for name in os.listdir(_HERE):
+ if name.startswith(TESTFILE_PREFIX):
+ _testfiles_created.add(name)
+ for name in _testfiles_created:
+ try:
+ safe_rmpath(name)
+ except UnicodeEncodeError as exc:
+ warn(exc)
+
+
# ===================================================================
# --- threads
# ===================================================================
@@ -226,7 +240,7 @@ def get_test_subprocess(cmd=None, **kwds):
"""Creates a python subprocess which does nothing for 60 secs and
return it as subprocess.Popen instance.
If "cmd" is specified that is used instead of python.
- By default stdout and stderr are redirected to /dev/null.
+ By default sdting and stderr are redirected to /dev/null.
It also attemps to make sure the process is in a reasonably
initialized state.
"""
@@ -685,21 +699,6 @@ def skip_on_not_implemented(only_if=None):
return decorator
-def cleanup():
- for name in os.listdir('.'):
- if name.startswith(TESTFILE_PREFIX):
- try:
- safe_rmpath(name)
- except UnicodeEncodeError as exc:
- warn(exc)
- for path in _testfiles_created:
- safe_rmpath(path)
-
-
-atexit.register(cleanup)
-atexit.register(lambda: DEVNULL.close())
-
-
# ===================================================================
# --- network
# ===================================================================