summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Harrison <frank@doublethefish.com>2020-10-20 07:44:41 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2020-11-27 08:42:30 +0100
commit08472654b40d813de33a98344f073feeb0911fdb (patch)
tree3cc01339ad7b9c68b565805c1c7c9e856375e778
parentc747dba6a38b2b0542d90c565e0f9220737bab24 (diff)
downloadpylint-git-08472654b40d813de33a98344f073feeb0911fdb.tar.gz
review fixes| Uses pytest's tmp_path fixture instead of custom context man
-rw-r--r--tests/profile/test_profile_against_externals.py42
1 files changed, 15 insertions, 27 deletions
diff --git a/tests/profile/test_profile_against_externals.py b/tests/profile/test_profile_against_externals.py
index 8de36c673..e7159264b 100644
--- a/tests/profile/test_profile_against_externals.py
+++ b/tests/profile/test_profile_against_externals.py
@@ -17,19 +17,6 @@ from pylint.lint import Run
from pylint.testutils import TestReporter as Reporter
-class TempdirGuard:
- """ creates and deletes a tmp-dir compatible with python2 and 3 """
-
- def __init__(self, prefix):
- self.path = tempfile.mkdtemp(prefix=prefix + "_")
-
- def __enter__(self):
- return self
-
- def __exit__(self, x_type, x_value, x_traceback):
- shutil.rmtree(self.path) # always clean up on exit
-
-
def _get_py_files(scanpath):
assert os.path.exists(scanpath), "Dir not found %s" % scanpath
@@ -53,21 +40,22 @@ def _get_py_files(scanpath):
@pytest.mark.parametrize(
"name,git_repo", [("numpy", "https://github.com/numpy/numpy.git")]
)
-def test_run(name, git_repo):
+def test_run(tmp_path, name, git_repo):
""" Runs pylint against external sources """
- with TempdirGuard(prefix=name) as checkoutdir:
- os.system(
- "git clone --depth=1 {git_repo} {checkoutdir}".format(
- git_repo=git_repo, checkoutdir=checkoutdir.path
- )
+ checkoutdir = tmp_path / name
+ checkoutdir.mkdir()
+ os.system(
+ "git clone --depth=1 {git_repo} {checkoutdir}".format(
+ git_repo=git_repo, checkoutdir=str(checkoutdir)
)
- filepaths = _get_py_files(scanpath=checkoutdir.path)
- print("Have %d files" % len(filepaths))
+ )
+ filepaths = _get_py_files(scanpath=str(checkoutdir))
+ print("Have %d files" % len(filepaths))
- runner = Run(filepaths, reporter=Reporter(), do_exit=False)
+ runner = Run(filepaths, reporter=Reporter(), do_exit=False)
- print(
- "Had %d files with %d messages"
- % (len(filepaths), len(runner.linter.reporter.messages))
- )
- pprint.pprint(runner.linter.reporter.messages)
+ print(
+ "Had %d files with %d messages"
+ % (len(filepaths), len(runner.linter.reporter.messages))
+ )
+ pprint.pprint(runner.linter.reporter.messages)