Skip to content

Commit

Permalink
Add test_return_codes check for valid subunit output
Browse files Browse the repository at this point in the history
This commit adds a check to the test_return_codes module to ensure that
valid subunit is being emitted when we say the command expects subunit
output. This check is accomplished by processing the output stream and
converting it to a list of dicts. Then we check that at least 1 test was
present in the output stream (which should be the case for all the
tests) to ensure it actually is processing the subunit.

This is a follow on unit test for #102
  • Loading branch information
mtreinish committed Sep 27, 2017
1 parent 51c08c5 commit 4197a10
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions stestr/tests/test_return_codes.py
Expand Up @@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import functools
import io
import os
import re
import shutil
Expand All @@ -20,6 +22,8 @@

import six
from six import StringIO
import subunit as subunit_lib
import testtools

from stestr.tests import base

Expand Down Expand Up @@ -67,6 +71,23 @@ def assertRunExit(self, cmd, expected, subunit=False):
self.assertEqual(p.returncode, expected,
"Expected return code: %s doesn't match actual "
"return code of: %s" % (expected, p.returncode))
output_stream = io.BytesIO(out)
stream = subunit_lib.ByteStreamToStreamResult(output_stream)
starts = testtools.StreamResult()
summary = testtools.StreamSummary()
tests = []

def _add_dict(test):
tests.append(test)

outcomes = testtools.StreamToDict(functools.partial(_add_dict))
result = testtools.CopyStreamResult([starts, outcomes, summary])
result.startTestRun()
try:
stream.run(result)
finally:
result.stopTestRun()
self.assertThat(len(tests), testtools.matchers.GreaterThan(0))

def test_parallel_passing(self):
self.assertRunExit('stestr run passing', 0)
Expand Down

0 comments on commit 4197a10

Please sign in to comment.