From 1fd1617427ea370994f0eedf448d38d981d3d9f8 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 19 Nov 2013 10:10:27 +0100 Subject: [PATCH] fix pexpect-3.0 compatibility for pytest's own tests. (fixes issue386) --- CHANGELOG | 3 +++ _pytest/pytester.py | 7 ++++--- testing/test_pdb.py | 12 +++++++----- tox.ini | 9 +-------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1ccac48d3..601415620 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Unreleased ----------------------------------- +- fix pexpect-3.0 compatibility for pytest's own tests. + (fixes issue386) + - allow nested parametrize-value markers, thanks James Lan for the PR. - fix unicode handling with new monkeypatch.setattr(import_path, value) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 8c1e73582..4805451e5 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -516,15 +516,16 @@ class TmpTestdir: return self.spawn(cmd, expect_timeout=expect_timeout) def spawn(self, cmd, expect_timeout=10.0): - pexpect = py.test.importorskip("pexpect", "2.4") + pexpect = py.test.importorskip("pexpect", "3.0") if hasattr(sys, 'pypy_version_info') and '64' in py.std.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") - child = pexpect.spawn(cmd, logfile=logfile.open("w")) + logfile = self.tmpdir.join("spawn.out").open("wb") + child = pexpect.spawn(cmd, logfile=logfile) + self.request.addfinalizer(logfile.close) child.timeout = expect_timeout return child diff --git a/testing/test_pdb.py b/testing/test_pdb.py index a8c4d9f79..4cdf06e75 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -1,3 +1,4 @@ + import py import sys @@ -62,7 +63,7 @@ class TestPDB: child.expect(".*i = 0") child.expect("(Pdb)") child.sendeof() - rest = child.read() + rest = child.read().decode("utf8") assert "1 failed" in rest assert "def test_1" not in rest if child.isalive(): @@ -127,7 +128,7 @@ class TestPDB: child.expect("x = 3") child.expect("(Pdb)") child.sendeof() - rest = child.read() + rest = child.read().decode("utf-8") assert "1 failed" in rest assert "def test_1" in rest assert "hello17" in rest # out is captured @@ -144,7 +145,7 @@ class TestPDB: child.expect("test_1") child.expect("(Pdb)") child.sendeof() - rest = child.read() + rest = child.read().decode("utf8") assert "1 failed" in rest assert "reading from stdin while output" not in rest if child.isalive(): @@ -182,7 +183,7 @@ class TestPDB: child.expect("0") child.expect("(Pdb)") child.sendeof() - rest = child.read() + rest = child.read().decode("utf8") assert "1 failed" in rest if child.isalive(): child.wait() @@ -206,7 +207,7 @@ class TestPDB: child.sendline('c') child.expect("x = 4") child.sendeof() - rest = child.read() + rest = child.read().decode("utf8") assert "1 failed" in rest assert "def test_1" in rest assert "hello17" in rest # out is captured @@ -238,6 +239,7 @@ class TestPDB: child.expect("x = 5") child.sendeof() child.wait() + def test_pdb_collection_failure_is_shown(self, testdir): p1 = testdir.makepyfile("""xxx """) result = testdir.runpytest("--pdb", p1) diff --git a/tox.ini b/tox.ini index cb95faffc..ae14220fc 100644 --- a/tox.ini +++ b/tox.ini @@ -16,6 +16,7 @@ commands= py.test --genscript=pytest1 [testenv:py25] setenv = PIP_INSECURE=1 +deps=nose [testenv:flakes] changedir= @@ -55,14 +56,6 @@ changedir=. commands=py.test --doctest-modules _pytest deps= -[testenv:py32] -deps= - nose - -[testenv:py33] -deps= - nose - [testenv:doc] basepython=python changedir=doc/en