From 11ec96a927e5571f39ab290d31fbb41200c791b8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 21 Oct 2016 12:10:35 -0400 Subject: [PATCH 1/3] Extract child flush as a staticmethod --- testing/test_pdb.py | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index d79d71262..aecf51bbc 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -76,6 +76,10 @@ class TestPDB: rest = child.read().decode("utf8") assert "1 failed" in rest assert "def test_1" not in rest + self.flush(child) + + @staticmethod + def flush(child): if child.isalive(): child.wait() @@ -95,8 +99,7 @@ class TestPDB: child.sendeof() rest = child.read().decode("utf8") assert 'debug.me' in rest - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_interaction_capture(self, testdir): p1 = testdir.makepyfile(""" @@ -111,8 +114,7 @@ class TestPDB: rest = child.read().decode("utf8") assert "1 failed" in rest assert "getrekt" not in rest - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_interaction_exception(self, testdir): p1 = testdir.makepyfile(""" @@ -130,8 +132,7 @@ class TestPDB: child.expect(".*function") child.sendeof() child.expect("1 failed") - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_interaction_on_collection_issue181(self, testdir): p1 = testdir.makepyfile(""" @@ -143,8 +144,7 @@ class TestPDB: child.expect("(Pdb)") child.sendeof() child.expect("1 error") - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_interaction_on_internal_error(self, testdir): testdir.makeconftest(""" @@ -156,8 +156,7 @@ class TestPDB: #child.expect(".*import pytest.*") child.expect("(Pdb)") child.sendeof() - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_interaction_capturing_simple(self, testdir): p1 = testdir.makepyfile(""" @@ -177,8 +176,7 @@ class TestPDB: assert "1 failed" in rest assert "def test_1" in rest assert "hello17" in rest # out is captured - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_set_trace_interception(self, testdir): p1 = testdir.makepyfile(""" @@ -193,8 +191,7 @@ class TestPDB: rest = child.read().decode("utf8") assert "1 failed" in rest assert "reading from stdin while output" not in rest - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_and_capsys(self, testdir): p1 = testdir.makepyfile(""" @@ -209,8 +206,7 @@ class TestPDB: child.expect("hello1") child.sendeof() child.read() - if child.isalive(): - child.wait() + self.flush(child) def test_set_trace_capturing_afterwards(self, testdir): p1 = testdir.makepyfile(""" @@ -229,8 +225,7 @@ class TestPDB: child.expect("hello") child.sendeof() child.read() - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_interaction_doctest(self, testdir): p1 = testdir.makepyfile(""" @@ -249,8 +244,7 @@ class TestPDB: child.sendeof() rest = child.read().decode("utf8") assert "1 failed" in rest - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_interaction_capturing_twice(self, testdir): p1 = testdir.makepyfile(""" @@ -276,8 +270,7 @@ class TestPDB: assert "def test_1" in rest assert "hello17" in rest # out is captured assert "hello18" in rest # out is captured - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_used_outside_test(self, testdir): p1 = testdir.makepyfile(""" @@ -331,8 +324,7 @@ class TestPDB: child.expect("enter_pdb_hook") child.send('c\n') child.sendeof() - if child.isalive(): - child.wait() + self.flush(child) def test_pdb_custom_cls(self, testdir): called = [] From 60a347aeb51582f6fee87497dfdb4f079a6f5c82 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 21 Oct 2016 12:11:35 -0400 Subject: [PATCH 2/3] Also use flush where wait was called unconditionally --- testing/test_pdb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index aecf51bbc..062ae1fb9 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -281,7 +281,7 @@ class TestPDB: child = testdir.spawn("%s %s" %(sys.executable, p1)) child.expect("x = 5") child.sendeof() - child.wait() + self.flush(child) def test_pdb_used_in_generate_tests(self, testdir): p1 = testdir.makepyfile(""" @@ -295,7 +295,7 @@ class TestPDB: child = testdir.spawn_pytest(str(p1)) child.expect("x = 5") child.sendeof() - child.wait() + self.flush(child) def test_pdb_collection_failure_is_shown(self, testdir): p1 = testdir.makepyfile("""xxx """) From f2c01c5407f3c7853bdd463b8aa2856e3a6398e1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 21 Oct 2016 12:36:42 -0400 Subject: [PATCH 3/3] Restore pexpect tests and bypass isalive/wait on macOS. Ref #2022. --- _pytest/pytester.py | 2 -- testing/test_pdb.py | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 651160cc7..a8bb39794 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -1002,8 +1002,6 @@ class Testdir: pexpect = pytest.importorskip("pexpect", "3.0") if hasattr(sys, 'pypy_version_info') and '64' in platform.machine(): pytest.skip("pypy-64 bit not supported") - if sys.platform == "darwin": - pytest.xfail("pexpect does not work reliably on darwin?!") if sys.platform.startswith("freebsd"): pytest.xfail("pexpect does not work reliably on freebsd") logfile = self.tmpdir.join("spawn.out").open("wb") diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 062ae1fb9..b22f5128e 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -1,4 +1,5 @@ import sys +import platform import _pytest._code import pytest @@ -80,6 +81,8 @@ class TestPDB: @staticmethod def flush(child): + if platform.system() == 'Darwin': + return if child.isalive(): child.wait()