From 430c123e213e1117c2cb6ec20c75a77acdae6c65 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 13 Feb 2019 22:42:04 +0100 Subject: [PATCH] terminal: write_fspath_result: work around py bug --- src/_pytest/terminal.py | 4 +++- testing/test_assertrewrite.py | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index f4f8b3dd211..ec6473d110e 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -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 diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index a852277cc2f..bfb6acfabf5 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -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 @@ -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 """,