Skip to content

Commit 0847265

Browse files
doublethefishPierre-Sassoulas
authored andcommitted
review fixes| Uses pytest's tmp_path fixture instead of custom context man
1 parent c747dba commit 0847265

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

tests/profile/test_profile_against_externals.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@
1717
from pylint.testutils import TestReporter as Reporter
1818

1919

20-
class TempdirGuard:
21-
""" creates and deletes a tmp-dir compatible with python2 and 3 """
22-
23-
def __init__(self, prefix):
24-
self.path = tempfile.mkdtemp(prefix=prefix + "_")
25-
26-
def __enter__(self):
27-
return self
28-
29-
def __exit__(self, x_type, x_value, x_traceback):
30-
shutil.rmtree(self.path) # always clean up on exit
31-
32-
3320
def _get_py_files(scanpath):
3421
assert os.path.exists(scanpath), "Dir not found %s" % scanpath
3522

@@ -53,21 +40,22 @@ def _get_py_files(scanpath):
5340
@pytest.mark.parametrize(
5441
"name,git_repo", [("numpy", "https://github.com/numpy/numpy.git")]
5542
)
56-
def test_run(name, git_repo):
43+
def test_run(tmp_path, name, git_repo):
5744
""" Runs pylint against external sources """
58-
with TempdirGuard(prefix=name) as checkoutdir:
59-
os.system(
60-
"git clone --depth=1 {git_repo} {checkoutdir}".format(
61-
git_repo=git_repo, checkoutdir=checkoutdir.path
62-
)
45+
checkoutdir = tmp_path / name
46+
checkoutdir.mkdir()
47+
os.system(
48+
"git clone --depth=1 {git_repo} {checkoutdir}".format(
49+
git_repo=git_repo, checkoutdir=str(checkoutdir)
6350
)
64-
filepaths = _get_py_files(scanpath=checkoutdir.path)
65-
print("Have %d files" % len(filepaths))
51+
)
52+
filepaths = _get_py_files(scanpath=str(checkoutdir))
53+
print("Have %d files" % len(filepaths))
6654

67-
runner = Run(filepaths, reporter=Reporter(), do_exit=False)
55+
runner = Run(filepaths, reporter=Reporter(), do_exit=False)
6856

69-
print(
70-
"Had %d files with %d messages"
71-
% (len(filepaths), len(runner.linter.reporter.messages))
72-
)
73-
pprint.pprint(runner.linter.reporter.messages)
57+
print(
58+
"Had %d files with %d messages"
59+
% (len(filepaths), len(runner.linter.reporter.messages))
60+
)
61+
pprint.pprint(runner.linter.reporter.messages)

0 commit comments

Comments
 (0)