def pseudo_keyboard_interrupt(self, testdir, linecomp, verbose=False):
     modcol = testdir.getmodulecol("""
         def test_foobar():
             assert 0
         def test_spamegg():
             import py; py.test.skip('skip me please!')
         def test_interrupt_me():
             raise KeyboardInterrupt   # simulating the user
     """, configargs=("-v",)*verbose)
     #""", configargs=("--showskipsummary",) + ("-v",)*verbose)
     rep = TerminalReporter(modcol.config, file=linecomp.stringio)
     modcol.config.bus.register(rep)
     bus = modcol.config.bus
     bus.notify("testrunstart", event.TestrunStart())
     try:
         for item in testdir.genitems([modcol]):
             bus.notify("itemtestreport", basic_run_report(item))
     except KeyboardInterrupt:
         excinfo = py.code.ExceptionInfo()
     else:
         py.test.fail("no KeyboardInterrupt??")
     s = linecomp.stringio.getvalue()
     if not verbose:
         assert s.find("_keyboard_interrupt.py Fs") != -1
     bus.notify("testrunfinish", event.TestrunFinish(exitstatus=2, excinfo=excinfo))
     text = linecomp.stringio.getvalue()
     linecomp.assert_contains_lines([
         "    def test_foobar():",
         ">       assert 0",
         "E       assert 0",
     ])
     #assert "Skipped: 'skip me please!'" in text
     assert "_keyboard_interrupt.py:6: KeyboardInterrupt" in text
     see_details = "raise KeyboardInterrupt   # simulating the user" in text
     assert see_details == verbose
 def test_pass_skip_fail(self, testdir, linecomp):
     modcol = testdir.getmodulecol("""
         import py
         def test_ok():
             pass
         def test_skip():
             py.test.skip("xx")
         def test_func():
             assert 0
     """)
     rep = TerminalReporter(modcol.config, file=linecomp.stringio)
     rep.config.bus.register(rep)
     rep.config.bus.notify("testrunstart", event.TestrunStart())
     
     for item in testdir.genitems([modcol]):
         ev = basic_run_report(item) 
         rep.config.bus.notify("itemtestreport", ev)
     linecomp.assert_contains_lines([
             "*test_pass_skip_fail.py .sF"
     ])
     rep.config.bus.notify("testrunfinish", event.TestrunFinish())
     linecomp.assert_contains_lines([
         "    def test_func():",
         ">       assert 0",
         "E       assert 0",
     ])
 def test_tb_option(self, testdir, linecomp):
     # XXX usage of testdir and event bus
     for tbopt in ["long", "short", "no"]:
         print 'testing --tb=%s...' % tbopt
         modcol = testdir.getmodulecol("""
             import py
             def g():
                 raise IndexError
             def test_func():
                 print 6*7
                 g()  # --calling--
         """, configargs=("--tb=%s" % tbopt,))
         rep = TerminalReporter(modcol.config, file=linecomp.stringio)
         rep.config.bus.register(rep)
         rep.config.bus.notify("testrunstart", event.TestrunStart())
         rep.config.bus.notify("testrunstart", event.TestrunStart())
         for item in testdir.genitems([modcol]):
             rep.config.bus.notify("itemtestreport", basic_run_report(item))
         rep.config.bus.notify("testrunfinish", event.TestrunFinish())
         s = linecomp.stringio.getvalue()
         if tbopt == "long":
             print s
             assert 'print 6*7' in s
         else:
             assert 'print 6*7' not in s
         if tbopt != "no":
             assert '--calling--' in s
             assert 'IndexError' in s
         else:
             assert 'FAILURES' not in s
             assert '--calling--' not in s
             assert 'IndexError' not in s
         linecomp.stringio.truncate(0)
    def test_pass_skip_fail_verbose(self, testdir, linecomp):
        modcol = testdir.getmodulecol("""
            import py
            def test_ok():
                pass
            def test_skip():
                py.test.skip("xx")
            def test_func():
                assert 0
        """, configargs=("-v",))
        rep = TerminalReporter(modcol.config, file=linecomp.stringio)
        rep.config.bus.register(rep)
        rep.config.bus.notify("testrunstart", event.TestrunStart())
        items = modcol.collect()
        rep.config.option.debug = True # 
        for item in items:
            rep.config.bus.notify("itemstart", item, None)
            s = linecomp.stringio.getvalue().strip()
            assert s.endswith(item.name)
            rep.config.bus.notify("itemtestreport", basic_run_report(item))

        linecomp.assert_contains_lines([
            "*test_pass_skip_fail_verbose.py:2: *test_ok*PASS*",
            "*test_pass_skip_fail_verbose.py:4: *test_skip*SKIP*",
            "*test_pass_skip_fail_verbose.py:6: *test_func*FAIL*",
        ])
        rep.config.bus.notify("testrunfinish", event.TestrunFinish())
        linecomp.assert_contains_lines([
            "    def test_func():",
            ">       assert 0",
            "E       assert 0",
        ])
Esempio n. 5
0
    def test_pass_skip_fail_verbose(self):
        modcol = self.getmodulecol("""
            import py
            def test_ok():
                pass
            def test_skip():
                py.test.skip("xx")
            def test_func():
                assert 0
        """, configargs=("-v",), withsession=True)
        stringio = py.std.cStringIO.StringIO()
        rep = TerminalReporter(modcol._config, file=stringio)
        rep.processevent(event.TestrunStart())
        items = modcol.collect()
        for item in items:
            rep.processevent(event.ItemStart(item))
            s = stringio.getvalue().strip()
            assert s.endswith(item.name)
            ev = basic_run_report(item) 
            rep.processevent(ev)

        assert_stringio_contains_lines(stringio, [
            "*test_pass_skip_fail_verbose.py:2: *test_ok*PASS",
            "*test_pass_skip_fail_verbose.py:4: *test_skip*SKIP",
            "*test_pass_skip_fail_verbose.py:6: *test_func*FAIL",
        ])
        rep.processevent(event.TestrunFinish())
        assert_stringio_contains_lines(stringio, [
            "    def test_func():",
            ">       assert 0",
            "E       assert 0",
        ])
Esempio n. 6
0
 def test_keyboard_interrupt(self, verbose=False):
     modcol = self.getmodulecol("""
         def test_foobar():
             assert 0
         def test_spamegg():
             import py; py.test.skip('skip me please!')
         def test_interrupt_me():
             raise KeyboardInterrupt   # simulating the user
     """, configargs=("--showskipsummary",) + ("-v",)*verbose,
          withsession=True)
     stringio = py.std.cStringIO.StringIO()
     rep = TerminalReporter(modcol._config, bus=self.session.bus, file=stringio)
     rep.processevent(event.TestrunStart())
     try:
         for item in self.session.genitems([modcol]):
             ev = basic_run_report(item) 
             rep.processevent(ev)
     except KeyboardInterrupt:
         excinfo = py.code.ExceptionInfo()
     else:
         py.test.fail("no KeyboardInterrupt??")
     s = popvalue(stringio)
     if not verbose:
         assert s.find("_keyboard_interrupt.py Fs") != -1
     rep.processevent(event.TestrunFinish(exitstatus=2, excinfo=excinfo))
     assert_stringio_contains_lines(stringio, [
         "    def test_foobar():",
         ">       assert 0",
         "E       assert 0",
     ])
     text = stringio.getvalue()
     assert "Skipped: 'skip me please!'" in text
     assert "_keyboard_interrupt.py:6: KeyboardInterrupt" in text
     see_details = "raise KeyboardInterrupt   # simulating the user" in text
     assert see_details == verbose
Esempio n. 7
0
 def test_tb_option(self):
     for tbopt in ["no", "short", "long"]:
         print 'testing --tb=%s...' % tbopt
         modcol = self.getmodulecol("""
             import py
             def g():
                 raise IndexError
             def test_func():
                 print 6*7
                 g()  # --calling--
         """, configargs=("--tb=%s" % tbopt,), withsession=True)
         stringio = py.std.cStringIO.StringIO()
         rep = TerminalReporter(modcol._config, file=stringio)
         rep.processevent(event.TestrunStart())
         for item in self.session.genitems([modcol]):
             ev = basic_run_report(item) 
             rep.processevent(ev)
         rep.processevent(event.TestrunFinish())
         s = popvalue(stringio)
         if tbopt == "long":
             assert 'print 6*7' in s
         else:
             assert 'print 6*7' not in s
         if tbopt != "no":
             assert '--calling--' in s
             assert 'IndexError' in s
         else:
             assert 'FAILURES' not in s
             assert '--calling--' not in s
             assert 'IndexError' not in s
 def test_looponfailreport(self, testdir, linecomp):
     modcol = testdir.getmodulecol("""
         def test_fail():
             assert 0
         def test_fail2():
             raise ValueError()
     """)
     rep = TerminalReporter(modcol.config, file=linecomp.stringio)
     reports = [basic_run_report(x) for x in modcol.collect()]
     rep.pyevent_looponfailinfo(event.LooponfailingInfo(reports, [modcol.config.topdir]))
     linecomp.assert_contains_lines([
         "*test_looponfailreport.py:2: assert 0",
         "*test_looponfailreport.py:4: ValueError*",
         "*waiting*", 
         "*%s*" % (modcol.config.topdir),
     ])
Esempio n. 9
0
 def test_looponfailingreport(self):
     modcol = self.getmodulecol("""
         def test_fail():
             assert 0
         def test_fail2():
             raise ValueError()
     """)
     stringio = py.std.cStringIO.StringIO()
     rep = TerminalReporter(modcol._config, file=stringio)
     reports = [basic_run_report(x) for x in modcol.collect()]
     rep.processevent(event.LooponfailingInfo(reports, [modcol._config.topdir]))
     assert_stringio_contains_lines(stringio, [
         "*test_looponfailingreport.py:2: assert 0",
         "*test_looponfailingreport.py:4: ValueError*",
         "*waiting*", 
         "*%s*" % (modcol._config.topdir),
     ])
Esempio n. 10
0
 def test_pass_skip_fail(self):
     modcol = self.getmodulecol("""
         import py
         def test_ok():
             pass
         def test_skip():
             py.test.skip("xx")
         def test_func():
             assert 0
     """, withsession=True)
     stringio = py.std.cStringIO.StringIO()
     rep = TerminalReporter(modcol._config, file=stringio)
     rep.processevent(event.TestrunStart())
     for item in self.session.genitems([modcol]):
         ev = basic_run_report(item) 
         rep.processevent(ev)
     s = popvalue(stringio)
     assert s.find("test_pass_skip_fail.py .sF") != -1
     rep.processevent(event.TestrunFinish())
     assert_stringio_contains_lines(stringio, [
         "    def test_func():",
         ">       assert 0",
         "E       assert 0",
     ])