Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py36+: remove _pytest.compat.fspath #7839

Merged
merged 1 commit into from Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/_pytest/assertion/rewrite.py
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions src/_pytest/compat.py
Expand Up @@ -2,7 +2,6 @@
import enum
import functools
import inspect
import os
import re
import sys
from contextlib import contextmanager
Expand Down Expand Up @@ -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)
Expand Down