Exemplo n.º 1
0
 def test_default(self):
     byte_stream = BytesIO()
     stream = StreamResultToBytes(byte_stream)
     stream.status(test_id="foo", test_status="inprogress")
     stream.status(test_id="foo", test_status="skip")
     output = self.run_command([], byte_stream.getvalue())
     events = StreamResult()
     ByteStreamToStreamResult(BytesIO(output)).run(events)
     ids = set(event[1] for event in events._events)
     self.assertEqual([
         ('status', 'foo', 'inprogress'),
         ('status', 'foo', 'skip'),
         ], [event[:3] for event in events._events])
Exemplo n.º 2
0
 def test_default(self):
     byte_stream = BytesIO()
     stream = StreamResultToBytes(byte_stream)
     stream.status(test_id="foo", test_status="inprogress")
     stream.status(test_id="foo", test_status="skip")
     output = self.run_command([], byte_stream.getvalue())
     events = StreamResult()
     ByteStreamToStreamResult(BytesIO(output)).run(events)
     ids = set(event[1] for event in events._events)
     self.assertEqual([
         ('status', 'foo', 'inprogress'),
         ('status', 'foo', 'skip'),
     ], [event[:3] for event in events._events])
Exemplo n.º 3
0
 def _list(self, test):
     test_ids, errors = list_test(test)
     try:
         fileno = self.stream.fileno()
     except:
         fileno = None
     if fileno is not None:
         stream = os.fdopen(fileno, "wb", 0)
     else:
         stream = self.stream
     result = StreamResultToBytes(stream)
     for test_id in test_ids:
         result.status(test_id=test_id, test_status="exists")
     return result, errors
Exemplo n.º 4
0
 def _list(self, test):
     test_ids, errors = list_test(test)
     try:
         fileno = self.stream.fileno()
     except:
         fileno = None
     if fileno is not None:
         stream = os.fdopen(fileno, 'wb', 0)
     else:
         stream = self.stream
     result = StreamResultToBytes(stream)
     for test_id in test_ids:
         result.status(test_id=test_id, test_status='exists')
     return result, errors
Exemplo n.º 5
0
 def test_tags(self):
     byte_stream = BytesIO()
     stream = StreamResultToBytes(byte_stream)
     stream.status(
         test_id="foo", test_status="inprogress", test_tags=set(["a"]))
     stream.status(
         test_id="foo", test_status="success", test_tags=set(["a"]))
     stream.status(test_id="bar", test_status="inprogress")
     stream.status(test_id="bar", test_status="inprogress")
     stream.status(
         test_id="baz", test_status="inprogress", test_tags=set(["a"]))
     stream.status(
         test_id="baz", test_status="success", test_tags=set(["a"]))
     output = self.run_command(
         ['-s', '--with-tag', 'a'], byte_stream.getvalue())
     events = StreamResult()
     ByteStreamToStreamResult(BytesIO(output)).run(events)
     ids = set(event[1] for event in events._events)
     self.assertEqual(set(['foo', 'baz']), ids)
Exemplo n.º 6
0
 def test_tags(self):
     byte_stream = BytesIO()
     stream = StreamResultToBytes(byte_stream)
     stream.status(test_id="foo",
                   test_status="inprogress",
                   test_tags=set(["a"]))
     stream.status(test_id="foo",
                   test_status="success",
                   test_tags=set(["a"]))
     stream.status(test_id="bar", test_status="inprogress")
     stream.status(test_id="bar", test_status="inprogress")
     stream.status(test_id="baz",
                   test_status="inprogress",
                   test_tags=set(["a"]))
     stream.status(test_id="baz",
                   test_status="success",
                   test_tags=set(["a"]))
     output = self.run_command(['-s', '--with-tag', 'a'],
                               byte_stream.getvalue())
     events = StreamResult()
     ByteStreamToStreamResult(BytesIO(output)).run(events)
     ids = set(event[1] for event in events._events)
     self.assertEqual(set(['foo', 'baz']), ids)
Exemplo n.º 7
0
class SubunitTerminalReporter(TerminalReporter):
    def __init__(self, reporter):
        TerminalReporter.__init__(self, reporter.config)
        self.writer = self._tw
        self.tests_count = 0
        self.reports = []
        self.skipped = []
        self.failed = []
        self.result = StreamResultToBytes(self.writer._file)

    def _status(self, report, status):
        # task id
        test_id = report.nodeid

        # get time
        now = datetime.datetime.now(utc)

        # capture output
        writer=py.io.TerminalWriter(stringio=True)
        try:
            report.toterminal(writer)
        except:
            pass
        writer.stringio.seek(0)
        out = writer.stringio.read()
        out = str(out)

        # send status
        self.result.status(test_id=test_id,
                           test_status=status,
                           timestamp=now,
                           file_name=report.fspath,
                           file_bytes=out,
                           mime_type="text/plain; charset=utf8")

    def pytest_collectreport(self, report):
        pass

    def pytest_collection_finish(self, session):
        if self.config.option.collectonly:
            self._printcollecteditems(session.items)

    def pytest_collection(self):
        # Prevent shoving `collecting` message
        pass

    def report_collect(self, final=False):
        # Prevent shoving `collecting` message
        pass

    def pytest_sessionstart(self, session):
        pass

    def pytest_runtest_logstart(self, nodeid, location):
        pass

    def pytest_sessionfinish(self, session, exitstatus):
        # always exit with exitcode 0
        session.exitstatus = 0

    def pytest_runtest_logreport(self, report):
        self.reports.append(report)
        test_id = report.nodeid
        if report.when in ['setup', 'session']:
            self._status(report, 'exists')
            if report.outcome == 'passed':
                self._status(report, 'inprogress')
            if report.outcome == 'failed':
                self._status(report, 'fail')
        elif report.when in ['call']:
            if hasattr(report, "wasxfail"):
                if report.skipped:
                    self._status(report, 'xfail')
                elif report.failed:
                    self._status(report, 'uxsuccess')
            elif report.outcome == 'failed':
                self._status(report, 'fail')
                self.failed.append(test_id)
            elif report.outcome == 'skipped':
                self._status(report, 'skip')
                self.skipped.append(test_id)
        elif report.when in ['teardown']:
            if test_id not in self.skipped and test_id not in self.failed:
                if report.outcome == 'passed':
                    self._status(report, 'success')
                elif report.outcome == 'failed':
                    self._status(report, 'fail')
        else:
            raise Exception(str(report))

    def _printcollecteditems(self, items):
        for item in items:
            test_id = item.nodeid
            self.result.status(test_id=test_id, test_status='exists')

    def summary_stats(self):
        pass

    def summary_failures(self):
        # Prevent failure summary from being shown since we already
        # show the failure instantly after failure has occured.
        pass

    def summary_errors(self):
        # Prevent error summary from being shown since we already
        # show the error instantly after error has occured.
        pass
Exemplo n.º 8
0
 def test_passthrough(self):
     output = self.run_command([], b'hi thar')
     byte_stream = BytesIO()
     stream = StreamResultToBytes(byte_stream)
     stream.status(file_name="stdout", file_bytes=b'hi thar')
     self.assertEqual(byte_stream.getvalue(), output)
Exemplo n.º 9
0
 def test_passthrough(self):
     output = self.run_command([], b'hi thar')
     byte_stream = BytesIO()
     stream = StreamResultToBytes(byte_stream)
     stream.status(file_name="stdout", file_bytes=b'hi thar')
     self.assertEqual(byte_stream.getvalue(), output)