Skip to content

Commit

Permalink
terminal: write_fspath_result: work around py bug
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Feb 13, 2019
1 parent 266f5bf commit 430c123
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/_pytest/terminal.py
Expand Up @@ -261,7 +261,9 @@ def hasopt(self, char):

def write_fspath_result(self, nodeid, res, **markup):
fspath = self.config.rootdir.join(nodeid.split("::")[0])
if fspath != self.currentfspath:
# NOTE: explicitly check for None to work around py bug, and for less
# overhead in general (https://github.com/pytest-dev/py/pull/207).
if self.currentfspath is None or fspath != self.currentfspath:
if self.currentfspath is not None and self._show_progress_info:
self._write_progress_information_filling_space()
self.currentfspath = fspath
Expand Down
13 changes: 10 additions & 3 deletions testing/test_assertrewrite.py
Expand Up @@ -1308,10 +1308,17 @@ def test_simple_failure():
@pytest.mark.skipif(
sys.platform.startswith("win32"), reason="cannot remove cwd on Windows"
)
def test_cwd_changed(self, testdir):
def test_cwd_changed(self, testdir, monkeypatch):
# Setup conditions for py's fspath trying to import pathlib on py34
# always (previously triggered via xdist only).
# Ref: https://github.com/pytest-dev/py/pull/207
monkeypatch.setattr(sys, "path", [""] + sys.path)
if "pathlib" in sys.modules:
del sys.modules["pathlib"]

testdir.makepyfile(
**{
"test_bar.py": """
"test_setup_nonexisting_cwd.py": """
import os
import shutil
import tempfile
Expand All @@ -1320,7 +1327,7 @@ def test_cwd_changed(self, testdir):
os.chdir(d)
shutil.rmtree(d)
""",
"test_foo.py": """
"test_test.py": """
def test():
pass
""",
Expand Down

0 comments on commit 430c123

Please sign in to comment.