From fb701b538c404bd0687f7fb3ec40327cd5cf13d2 Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Thu, 1 Dec 2022 18:16:02 +0100 Subject: [PATCH] Use os.sep instead of os.path.sep. Signed-off-by: Daniel Scheffler --- src/_pytest/_argcomplete.py | 6 +++--- src/_pytest/_py/path.py | 4 ++-- src/_pytest/assertion/rewrite.py | 2 +- src/_pytest/pathlib.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/_pytest/_argcomplete.py b/src/_pytest/_argcomplete.py index 120f09ff6..6a8083770 100644 --- a/src/_pytest/_argcomplete.py +++ b/src/_pytest/_argcomplete.py @@ -78,15 +78,15 @@ class FastFilesCompleter: def __call__(self, prefix: str, **kwargs: Any) -> List[str]: # Only called on non option completions. - if os.path.sep in prefix[1:]: - prefix_dir = len(os.path.dirname(prefix) + os.path.sep) + if os.sep in prefix[1:]: + prefix_dir = len(os.path.dirname(prefix) + os.sep) else: prefix_dir = 0 completion = [] globbed = [] if "*" not in prefix and "?" not in prefix: # We are on unix, otherwise no bash. - if not prefix or prefix[-1] == os.path.sep: + if not prefix or prefix[-1] == os.sep: globbed.extend(glob(prefix + ".*")) prefix += "*" globbed.extend(glob(prefix)) diff --git a/src/_pytest/_py/path.py b/src/_pytest/_py/path.py index c3905d0d3..fb64830f8 100644 --- a/src/_pytest/_py/path.py +++ b/src/_pytest/_py/path.py @@ -796,7 +796,7 @@ class LocalPath: kw = {"exists": 1} return Checkers(self)._evaluate(kw) - _patternchars = set("*?[" + os.path.sep) + _patternchars = set("*?[" + os.sep) def listdir(self, fil=None, sort=None): """List directory contents, possibly filter by the given fil func @@ -1128,7 +1128,7 @@ class LocalPath: modfile = modfile[:-1] elif modfile.endswith("$py.class"): modfile = modfile[:-9] + ".py" - if modfile.endswith(os.path.sep + "__init__.py"): + if modfile.endswith(os.sep + "__init__.py"): if self.basename != "__init__.py": modfile = modfile[:-12] try: diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index cb64a33c0..e2648029c 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -180,7 +180,7 @@ class AssertionRewritingHook(importlib.abc.MetaPathFinder, importlib.abc.Loader) for initial_path in self.session._initialpaths: # Make something as c:/projects/my_project/path.py -> # ['c:', 'projects', 'my_project', 'path.py'] - parts = str(initial_path).split(os.path.sep) + parts = str(initial_path).split(os.sep) # add 'path' to basenames to be checked. self._basenames_to_check_rewrite.add(os.path.splitext(parts[-1])[0]) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 533335c66..1fc16f5cd 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -557,8 +557,8 @@ def import_path( if module_file.endswith((".pyc", ".pyo")): module_file = module_file[:-1] - if module_file.endswith(os.path.sep + "__init__.py"): - module_file = module_file[: -(len(os.path.sep + "__init__.py"))] + if module_file.endswith(os.sep + "__init__.py"): + module_file = module_file[: -(len(os.sep + "__init__.py"))] try: is_same = _is_same(str(path), module_file)