Skip to content

Commit 53ae55e

Browse files
committed
Combine test helpers: remove_files
1 parent 842f585 commit 53ae55e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

tests/helpers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""Helpers for coverage.py tests."""
55

66
import glob
7-
import itertools
87
import os
98
import re
109
import shutil
@@ -106,6 +105,13 @@ def re_line(text, pat):
106105
return lines[0]
107106

108107

108+
def remove_files(*patterns):
109+
"""Remove all files that match any of the patterns."""
110+
for pattern in patterns:
111+
for fname in glob.glob(pattern):
112+
os.remove(fname)
113+
114+
109115
class SuperModuleCleaner(ModuleCleaner):
110116
"""Remember the state of sys.modules and restore it later."""
111117

@@ -122,8 +128,7 @@ def clean_local_file_imports(self):
122128
# Also have to clean out the .pyc file, since the timestamp
123129
# resolution is only one second, a changed file might not be
124130
# picked up.
125-
for pyc in itertools.chain(glob.glob('*.pyc'), glob.glob('*$py.class')):
126-
os.remove(pyc)
131+
remove_files("*.pyc", "*$py.class")
127132
if os.path.exists("__pycache__"):
128133
shutil.rmtree("__pycache__")
129134

tests/test_concurrency.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from coverage.files import abs_file
2020

2121
from tests.coveragetest import CoverageTest
22+
from tests.helpers import remove_files
2223

2324

2425
# These libraries aren't always available, we'll skip tests if they aren't.
@@ -361,12 +362,6 @@ def process_worker_main(args):
361362
"""
362363

363364

364-
def remove_files(*patterns):
365-
for pattern in patterns:
366-
for fname in glob.glob(pattern):
367-
os.remove(fname)
368-
369-
370365
@flaky(max_runs=30) # Sometimes a test fails due to inherent randomness. Try more times.
371366
class MultiprocessingTest(CoverageTest):
372367
"""Test support of the multiprocessing module."""

0 commit comments

Comments
 (0)