diff --git a/py/_path/common.py b/py/_path/common.py index 2d490b56..958f98fb 100644 --- a/py/_path/common.py +++ b/py/_path/common.py @@ -37,6 +37,8 @@ def fspath(path): import pathlib except ImportError: pass + except FileNotFoundError: # Might happen in py34. + pass else: if isinstance(path, pathlib.PurePath): return py.builtin.text(path) diff --git a/testing/path/test_local.py b/testing/path/test_local.py index d52409e5..863157d6 100644 --- a/testing/path/test_local.py +++ b/testing/path/test_local.py @@ -174,7 +174,31 @@ def test_eq_with_strings(self, path1): assert path2 != path3 def test_eq_with_none(self, path1): - assert path1 != None # noqa + assert path1 != None # noqa: E711 + + @pytest.mark.skipif( + sys.platform.startswith("win32"), reason="cannot remove cwd on Windows" + ) + @pytest.mark.skipif( + sys.version_info < (3, 0) or sys.version_info >= (3, 5), + reason="only with Python 3 before 3.5" + ) + def test_eq_with_none_and_custom_fspath(self, monkeypatch, path1): + import os + import shutil + import tempfile + + d = tempfile.mkdtemp() + monkeypatch.chdir(d) + shutil.rmtree(d) + + monkeypatch.delitem(sys.modules, 'pathlib', raising=False) + monkeypatch.setattr(sys, 'path', [''] + sys.path) + + with pytest.raises(FileNotFoundError): + import pathlib # noqa: F401 + + assert path1 != None # noqa: E711 def test_eq_non_ascii_unicode(self, path1): path2 = path1.join(u'temp')