def test_capturing_basic_api(self, method): capouter = py.io.StdCaptureFD() old = sys.stdout, sys.stderr, sys.stdin try: capman = CaptureManager() capman.resumecapture(method) print "hello" out, err = capman.suspendcapture() if method == "no": assert old == (sys.stdout, sys.stderr, sys.stdin) else: assert out == "hello\n" capman.resumecapture(method) out, err = capman.suspendcapture() assert not out and not err finally: capouter.reset()
def test_juggle_capturings(self, testdir): capouter = py.io.StdCaptureFD() try: config = testdir.parseconfig(testdir.tmpdir) capman = CaptureManager() capman.resumecapture("fd") py.test.raises(ValueError, 'capman.resumecapture("fd")') py.test.raises(ValueError, 'capman.resumecapture("sys")') os.write(1, "hello\n") out, err = capman.suspendcapture() assert out == "hello\n" capman.resumecapture("sys") os.write(1, "hello\n") print >>sys.stderr, "world" out, err = capman.suspendcapture() assert not out assert err == "world\n" finally: capouter.reset()