From be43c7c67baf42ef4b2beb13cd8bb26c02094241 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 2 Oct 2020 12:20:51 -0700 Subject: [PATCH] py36+: remove _pytest.compat.fspath --- src/_pytest/assertion/rewrite.py | 15 +++++++-------- src/_pytest/compat.py | 13 ------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 0b737fc7810..28a206c27a3 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -33,7 +33,6 @@ from _pytest.assertion.util import ( # noqa: F401 format_explanation as _format_explanation, ) -from _pytest.compat import fspath from _pytest.config import Config from _pytest.main import Session from _pytest.pathlib import fnmatch_ex @@ -306,7 +305,7 @@ def _write_pyc( pyc: Path, ) -> bool: try: - with atomic_write(fspath(pyc), mode="wb", overwrite=True) as fp: + with atomic_write(os.fspath(pyc), mode="wb", overwrite=True) as fp: _write_pyc_fp(fp, source_stat, co) except OSError as e: state.trace("error writing pyc file at {}: {}".format(pyc, e)) @@ -336,7 +335,7 @@ def _write_pyc( try: _write_pyc_fp(fp, source_stat, co) - os.rename(proc_pyc, fspath(pyc)) + os.rename(proc_pyc, os.fspath(pyc)) except OSError as e: state.trace("error writing pyc file at {}: {}".format(pyc, e)) # we ignore any failure to write the cache file @@ -350,7 +349,7 @@ def _write_pyc( def _rewrite_test(fn: Path, config: Config) -> Tuple[os.stat_result, types.CodeType]: """Read and rewrite *fn* and return the code object.""" - fn_ = fspath(fn) + fn_ = os.fspath(fn) stat = os.stat(fn_) with open(fn_, "rb") as f: source = f.read() @@ -368,12 +367,12 @@ def _read_pyc( Return rewritten code if successful or None if not. """ try: - fp = open(fspath(pyc), "rb") + fp = open(os.fspath(pyc), "rb") except OSError: return None with fp: try: - stat_result = os.stat(fspath(source)) + stat_result = os.stat(os.fspath(source)) mtime = int(stat_result.st_mtime) size = stat_result.st_size data = fp.read(12) @@ -831,7 +830,7 @@ def visit_Assert(self, assert_: ast.Assert) -> List[ast.stmt]: "assertion is always true, perhaps remove parentheses?" ), category=None, - filename=fspath(self.module_path), + filename=os.fspath(self.module_path), lineno=assert_.lineno, ) @@ -1072,7 +1071,7 @@ def try_makedirs(cache_dir: Path) -> bool: Returns True if successful or if it already exists. """ try: - os.makedirs(fspath(cache_dir), exist_ok=True) + os.makedirs(os.fspath(cache_dir), exist_ok=True) except (FileNotFoundError, NotADirectoryError, FileExistsError): # One of the path components was not a directory: # - we're in a zip file diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 49b00c58e3b..cbfeb96bcf9 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -2,7 +2,6 @@ import enum import functools import inspect -import os import re import sys from contextlib import contextmanager @@ -55,18 +54,6 @@ def _format_args(func: Callable[..., Any]) -> str: REGEX_TYPE = type(re.compile("")) -if sys.version_info < (3, 6): - - def fspath(p): - """os.fspath replacement, useful to point out when we should replace it by the - real function once we drop py35.""" - return str(p) - - -else: - fspath = os.fspath - - def is_generator(func: object) -> bool: genfunc = inspect.isgeneratorfunction(func) return genfunc and not iscoroutinefunction(func)