diff --git a/src/_pytest/_py/path.py b/src/_pytest/_py/path.py index 585edd65d64..0792da22810 100644 --- a/src/_pytest/_py/path.py +++ b/src/_pytest/_py/path.py @@ -428,9 +428,9 @@ def __fspath__(self): class Visitor: def __init__(self, fil, rec, ignore, bf, sort): - if isinstance(fil, py.builtin._basestring): + if isinstance(fil, str): fil = FNMatcher(fil) - if isinstance(rec, py.builtin._basestring): + if isinstance(rec, str): self.rec = FNMatcher(rec) elif not hasattr(rec, "__call__") and rec: self.rec = lambda path: True @@ -882,7 +882,7 @@ def listdir(self, fil=None, sort=None): if fil is None and sort is None: names = error.checked_call(os.listdir, self.strpath) return map_as_list(self._fastjoin, names) - if isinstance(fil, py.builtin._basestring): + if isinstance(fil, str): if not self._patternchars.intersection(fil): child = self._fastjoin(fil) if exists(child.strpath): @@ -989,14 +989,14 @@ def write(self, data, mode="w", ensure=False): if ensure: self.dirpath().ensure(dir=1) if "b" in mode: - if not py.builtin._isbytes(data): + if not isinstance(data, bytes): raise ValueError("can only process bytes") else: - if not py.builtin._istext(data): - if not py.builtin._isbytes(data): + if not isinstance(data, str): + if not isinstance(data, bytes): data = str(data) else: - data = py.builtin._totext(data, sys.getdefaultencoding()) + data = data.decode(sys.getdefaultencoding()) f = self.open(mode) try: f.write(data) @@ -1221,7 +1221,8 @@ def pyimport(self, modname=None, ensuresyspath=True): mod.__file__ = str(self) sys.modules[modname] = mod try: - py.builtin.execfile(str(self), mod.__dict__) + with open(str(self), 'rb') as f: + exec(f.read(), mod.__dict__) except: del sys.modules[modname] raise @@ -1239,12 +1240,12 @@ def sysexec(self, *argv, **popen_opts): proc = Popen([str(self)] + argv, **popen_opts) stdout, stderr = proc.communicate() ret = proc.wait() - if py.builtin._isbytes(stdout): - stdout = py.builtin._totext(stdout, sys.getdefaultencoding()) + if isinstance(stdout, bytes): + stdout = stdout.decode(sys.getdefaultencoding()) if ret != 0: - if py.builtin._isbytes(stderr): - stderr = py.builtin._totext(stderr, sys.getdefaultencoding()) - raise py.process.cmdexec.Error( + if isinstance(stderr, bytes): + stderr = stderr.decode(sys.getdefaultencoding()) + raise RuntimeError( ret, ret, str(self), @@ -1262,7 +1263,7 @@ def sysfind(cls, name, checker=None, paths=None): but may work on cygwin. """ if isabs(name): - p = py.path.local(name) + p = local(name) if p.check(file=1): return p else: @@ -1288,7 +1289,7 @@ def sysfind(cls, name, checker=None, paths=None): for x in paths: for addext in tryadd: - p = py.path.local(x).join(name, abs=True) + addext + p = local(x).join(name, abs=True) + addext try: if p.check(file=1): if checker: @@ -1323,7 +1324,7 @@ def get_temproot(cls): """ import tempfile - return py.path.local(tempfile.gettempdir()) + return local(tempfile.gettempdir()) @classmethod def mkdtemp(cls, rootdir=None):