summaryrefslogtreecommitdiff
path: root/tests/helpers.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2019-12-17 07:37:45 -0500
committerNed Batchelder <ned@nedbatchelder.com>2019-12-17 07:37:45 -0500
commit53ae55e053a4e7358a5708b2c194d26851690439 (patch)
treef79f36bd9aee29e095b8b8cae04eac074113e043 /tests/helpers.py
parent842f5854e75362214ce4699d8707ccc81601900a (diff)
downloadpython-coveragepy-git-53ae55e053a4e7358a5708b2c194d26851690439.tar.gz
Combine test helpers: remove_files
Diffstat (limited to 'tests/helpers.py')
-rw-r--r--tests/helpers.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index bc9c3982..09ba485d 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -4,7 +4,6 @@
"""Helpers for coverage.py tests."""
import glob
-import itertools
import os
import re
import shutil
@@ -106,6 +105,13 @@ def re_line(text, pat):
return lines[0]
+def remove_files(*patterns):
+ """Remove all files that match any of the patterns."""
+ for pattern in patterns:
+ for fname in glob.glob(pattern):
+ os.remove(fname)
+
+
class SuperModuleCleaner(ModuleCleaner):
"""Remember the state of sys.modules and restore it later."""
@@ -122,8 +128,7 @@ class SuperModuleCleaner(ModuleCleaner):
# Also have to clean out the .pyc file, since the timestamp
# resolution is only one second, a changed file might not be
# picked up.
- for pyc in itertools.chain(glob.glob('*.pyc'), glob.glob('*$py.class')):
- os.remove(pyc)
+ remove_files("*.pyc", "*$py.class")
if os.path.exists("__pycache__"):
shutil.rmtree("__pycache__")