def test_trace_with_stuck_inprogress(self):
        output = io.BytesIO()
        stream = StreamResultToBytes(output)
        stream.startTestRun()
        stream.status(test_id='test_passes', test_status='inprogress',
                      timestamp=dt.now(UTC))
        stream.status(test_id='test_segfault', test_status='inprogress',
                      timestamp=dt.now(UTC))
        stream.status(test_id='test_passes', test_status='success',
                      timestamp=dt.now(UTC))
        stream.stopTestRun()
        output.seek(0)
        # capture stderr for test
        stderr = io.StringIO()
        sys_err = sys.stderr
        sys.stderr = stderr

        def restore_stderr():
            sys.stderr = sys_err

        self.addCleanup(restore_stderr)
        stdin = io.TextIOWrapper(io.BufferedReader(output))
        returncode = subunit_trace.trace(stdin, sys.stdout)
        self.assertEqual(1, returncode)
        stderr.seek(0)
        expected = """
The following tests exited without returning a status
and likely segfaulted or crashed Python:

\t* test_segfault
"""
        self.assertEqual(stderr.read(), expected)
 def test_trace_with_all_skips(self):
     regular_stream = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         'sample_streams/all_skips.subunit')
     bytes_ = io.BytesIO()
     with open(regular_stream, 'rb') as stream:
         bytes_.write(bytes(stream.read()))
     bytes_.seek(0)
     stdin = io.TextIOWrapper(io.BufferedReader(bytes_))
     returncode = subunit_trace.trace(stdin, sys.stdout)
     self.assertEqual(1, returncode)
Exemple #3
0
    case = latest_run.get_test()
    try:
        if repo_type == 'file':
            previous_run = repo.get_test_run(repo.latest_id() - 1)
        # TODO(mtreinish): add a repository api to get the previous_run to
        # unify this logic
        else:
            previous_run = None
    except KeyError:
        previous_run = None
    failed = False
    if not pretty_out:
        output_result = results.CLITestResult(latest_run.get_id, stdout,
                                              previous_run)
        summary = output_result.get_summary()
        output_result.startTestRun()
        try:
            case.run(output_result)
        finally:
            output_result.stopTestRun()
        failed = not results.wasSuccessful(summary)
    else:
        stream = latest_run.get_subunit_stream()
        failed = subunit_trace.trace(stream, stdout, post_fails=True,
                                     color=color,
                                     suppress_attachments=suppress_attachments)
    if failed:
        return 1
    else:
        return 0
Exemple #4
0
        output.output_stream(stream, output=stdout)
        # Exits 0 if we successfully wrote the stream.
        return 0
    case = latest_run.get_test()
    try:
        previous_run = repo.get_test_run(repo.latest_id() - 1)
    except KeyError:
        previous_run = None
    failed = False
    if not pretty_out:
        output_result = results.CLITestResult(latest_run.get_id, stdout,
                                              previous_run)
        summary = output_result.get_summary()
        output_result.startTestRun()
        try:
            case.run(output_result)
        finally:
            output_result.stopTestRun()
        failed = not results.wasSuccessful(summary)
    else:
        stream = latest_run.get_subunit_stream()
        failed = subunit_trace.trace(
            stream, stdout, post_fails=True, color=color,
            suppress_attachments=suppress_attachments,
            all_attachments=all_attachments,
            show_binary_attachments=show_binary_attachments)
    if failed:
        return 1
    else:
        return 0
Exemple #5
0
    try:
        if repo_type == 'file':
            previous_run = repo.get_test_run(repo.latest_id() - 1)
        # TODO(mtreinish): add a repository api to get the previous_run to
        # unify this logic
        else:
            previous_run = None
    except KeyError:
        previous_run = None
    failed = False
    if not pretty_out:
        output_result = results.CLITestResult(latest_run.get_id, stdout,
                                              previous_run)
        summary = output_result.get_summary()
        output_result.startTestRun()
        try:
            case.run(output_result)
        finally:
            output_result.stopTestRun()
        failed = not summary.wasSuccessful()
    else:
        stream = latest_run.get_subunit_stream()
        failed = subunit_trace.trace(stream,
                                     stdout,
                                     post_fails=True,
                                     color=color)
    if failed:
        return 1
    else:
        return 0