From 61885cd825e05631812a5772c3b9c90d43f8a3ca Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 6 May 2009 11:47:48 +0200 Subject: [PATCH] provide testdir.spawn_pytest for pexpect mediated interaction tests, kill code, yay. --HG-- branch : trunk --- py/test/plugin/pytest_pytester.py | 15 ++++++++++++++- py/test/testing/acceptance_test.py | 25 ++----------------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index ac8b953b6..68c876dd7 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -254,10 +254,14 @@ class TmpTestdir: return RunResult(ret, out, err) def runpybin(self, scriptname, *args): + fullargs = self._getpybinargs(scriptname) + args + return self.run(*fullargs) + + def _getpybinargs(self, scriptname): bindir = py.path.local(py.__file__).dirpath("bin") script = bindir.join(scriptname) assert script.check() - return self.run(py.std.sys.executable, script, *args) + return py.std.sys.executable, script def runpytest(self, *args): p = py.path.local.make_numbered_dir(prefix="runpytest-", @@ -265,6 +269,15 @@ class TmpTestdir: args = ('--basetemp=%s' % p, ) + args return self.runpybin("py.test", *args) + def spawn_pytest(self, string, expect_timeout=10.0): + pexpect = py.test.importorskip("pexpect", "2.3") + basetemp = self.tmpdir.mkdir("pexpect") + invoke = "%s %s" % self._getpybinargs("py.test") + cmd = "%s --basetemp=%s %s" % (invoke, basetemp, string) + child = pexpect.spawn(cmd, logfile=basetemp.join("spawn.out").open("w")) + child.timeout = expect_timeout + return child + class Event: def __init__(self, name, args, kwargs): self.name = name diff --git a/py/test/testing/acceptance_test.py b/py/test/testing/acceptance_test.py index 8f107d877..7edf4a413 100644 --- a/py/test/testing/acceptance_test.py +++ b/py/test/testing/acceptance_test.py @@ -1,7 +1,5 @@ import py -pydir = py.path.local(py.__file__).dirpath() -pytestpath = pydir.join("bin", "py.test") EXPECTTIMEOUT=10.0 class TestGeneralUsage: @@ -445,30 +443,13 @@ class TestDistribution: class TestInteractive: - def getspawn(self, tmpdir): - pexpect = py.test.importorskip("pexpect") - basetemp = tmpdir.mkdir("basetemp") - def spawn(cmd): - cmd = cmd + " --basetemp=" + str(basetemp) - return pexpect.spawn(cmd, logfile=tmpdir.join("spawn.out").open("w")) - return spawn - - def requirespexpect(self, version_needed): - pexpect = py.test.importorskip("pexpect") - ver = tuple(map(int, pexpect.__version__.split("."))) - if ver < version_needed: - py.test.skip("pexpect version %s needed" %(".".join(map(str, version_needed)))) - def test_pdb_interaction(self, testdir): - self.requirespexpect((2,3)) - spawn = self.getspawn(testdir.tmpdir) p1 = testdir.makepyfile(""" def test_1(): i = 0 assert i == 1 """) - child = spawn("%s %s --pdb %s" % (py.std.sys.executable, pytestpath, p1)) - child.timeout = EXPECTTIMEOUT + child = testdir.spawn_pytest("--pdb %s" % p1) #child.expect(".*def test_1.*") child.expect(".*i = 0.*") child.expect("(Pdb)") @@ -478,14 +459,12 @@ class TestInteractive: child.wait() def test_simple_looponfail_interaction(self, testdir): - spawn = self.getspawn(testdir.tmpdir) p1 = testdir.makepyfile(""" def test_1(): assert 1 == 0 """) p1.setmtime(p1.mtime() - 50.0) - child = spawn("%s %s --looponfail %s" % (py.std.sys.executable, pytestpath, p1)) - child.timeout = EXPECTTIMEOUT + child = testdir.spawn_pytest("--looponfail %s" % p1) child.expect("assert 1 == 0") child.expect("test_simple_looponfail_interaction.py:") child.expect("1 failed")