[pypy-commit] pypy pytest: use funcargs in the testrunner test to ease having recoverable output

RonnyPfannschmidt noreply at buildbot.pypy.org
Sat Jan 21 21:40:08 CET 2012


Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch: pytest
Changeset: r51609:a696d22b84c6
Date: 2012-01-21 20:08 +0100
http://bitbucket.org/pypy/pypy/changeset/a696d22b84c6/

Log:	use funcargs in the testrunner test to ease having recoverable
	output

diff --git a/testrunner/test/conftest.py b/testrunner/test/conftest.py
new file mode 100644
--- /dev/null
+++ b/testrunner/test/conftest.py
@@ -0,0 +1,6 @@
+
+def pytest_runtest_makereport(__multicall__, item):
+    report = __multicall__.execute()
+    if 'out' in item.funcargs:
+        report.sections.append(('out', item.funcargs['out'].read()))
+    return report
diff --git a/testrunner/test/test_runner.py b/testrunner/test/test_runner.py
--- a/testrunner/test/test_runner.py
+++ b/testrunner/test/test_runner.py
@@ -53,49 +53,44 @@
     assert not should_report_failure("F Def\n. Ghi\n. Jkl\n")
 
 
+
 class TestRunHelper(object):
+    def pytest_funcarg__out(self, request):
+        tmpdir = request.getfuncargvalue('tmpdir')
+        return tmpdir.ensure('out')
 
-    def setup_method(self, meth):
-        h, self.fn = tempfile.mkstemp()
-        os.close(h)
+    def test_run(self, out):
+        res = runner.run([sys.executable, "-c", "print 42"], '.', out)
+        assert res == 0
+        assert out.read() == "42\n"
 
-    def teardown_method(self, meth):
-        os.unlink(self.fn)
-
-    def test_run(self):
-        res = runner.run([sys.executable, "-c", "print 42"], '.',
-                         py.path.local(self.fn))
-        assert res == 0
-        out = py.path.local(self.fn).read('r')
-        assert out == "42\n"
-
-    def test_error(self):
-        res = runner.run([sys.executable, "-c", "import sys; sys.exit(3)"], '.', py.path.local(self.fn))
+    def test_error(self, out):
+        res = runner.run([sys.executable, "-c", "import sys; sys.exit(3)"], '.', out)
         assert res == 3
 
-    def test_signal(self):
+    def test_signal(self, out):
         if sys.platform == 'win32':
             py.test.skip("no death by signal on windows")
-        res = runner.run([sys.executable, "-c", "import os; os.kill(os.getpid(), 9)"], '.', py.path.local(self.fn))
+        res = runner.run([sys.executable, "-c", "import os; os.kill(os.getpid(), 9)"], '.', out)
         assert res == -9
 
-    def test_timeout(self):
-        res = runner.run([sys.executable, "-c", "while True: pass"], '.', py.path.local(self.fn), timeout=3)
+    def test_timeout(self, out):
+        res = runner.run([sys.executable, "-c", "while True: pass"], '.', out, timeout=3)
         assert res == -999
 
-    def test_timeout_lock(self):
-        res = runner.run([sys.executable, "-c", "import threading; l=threading.Lock(); l.acquire(); l.acquire()"], '.', py.path.local(self.fn), timeout=3)
+    def test_timeout_lock(self, out):
+        res = runner.run([sys.executable, "-c", "import threading; l=threading.Lock(); l.acquire(); l.acquire()"], '.', out, timeout=3)
         assert res == -999
 
-    def test_timeout_syscall(self):
-        res = runner.run([sys.executable, "-c", "import socket; s=s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.bind(('', 0)); s.recv(1000)"], '.', py.path.local(self.fn), timeout=3)
+    def test_timeout_syscall(self, out):
+        res = runner.run([sys.executable, "-c", "import socket; s=s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.bind(('', 0)); s.recv(1000)"], '.', out, timeout=3)
         assert res == -999        
 
-    def test_timeout_success(self):
+    def test_timeout_success(self, out):
         res = runner.run([sys.executable, "-c", "print 42"], '.',
-                         py.path.local(self.fn), timeout=2)
+                         out, timeout=2)
         assert res == 0
-        out = py.path.local(self.fn).read('r')
+        out = out.read()
         assert out == "42\n"        
 
 


More information about the pypy-commit mailing list