Skip to content

Commit

Permalink
Make --subunit --list-tests only print test IDs
Browse files Browse the repository at this point in the history
This is not really correct, but it simplifies Launchpad's testrepository
plumbing for now.

Based on work by Benji York in Launchpad's zope.testing fork.
  • Loading branch information
cjwatson committed Oct 19, 2019
1 parent c350911 commit 2a12123
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
17 changes: 12 additions & 5 deletions src/zope/testrunner/formatter.py
Expand Up @@ -1055,12 +1055,8 @@ def _emit_exists(self, test):

def list_of_tests(self, tests, layer_name):
"""Report a list of test names."""
self._enter_layer(layer_name)
for test in tests:
self._subunit.startTest(test)
self._emit_exists(test)
self._subunit.stopTest(test)
self._exit_layer(layer_name)
print(test.id())

def garbage(self, garbage):
"""Report garbage generated by tests."""
Expand Down Expand Up @@ -1312,6 +1308,17 @@ def _subunit_factory(cls, stream):
result.startTestRun()
return result

# Undo Launchpad's subunit v1 hack to print test IDs directly rather
# than using a subunit stream; we only use that in v1 mode.
def list_of_tests(self, tests, layer_name):
"""Report a list of test names."""
self._enter_layer(layer_name)
for test in tests:
self._subunit.startTest(test)
self._emit_exists(test)
self._subunit.stopTest(test)
self._exit_layer(layer_name)

def error(self, message):
"""Report an error."""
# XXX: Mostly used for user errors, sometimes used for errors in the
Expand Down
33 changes: 10 additions & 23 deletions src/zope/testrunner/tests/testrunner-subunit.rst
Expand Up @@ -107,32 +107,19 @@ Once the layer is set up, all future tests are tagged with
Listing tests
-------------

A subunit stream is a stream of test results, more or less, so the most
natural way of listing tests in subunit is to simply emit successful test
results without actually running the tests.

Note that in this stream, we don't emit fake tests for the layer set up and
tear down, because it simply doesn't happen.

We also don't include the dependent layers in the stream (in this case Layer1
and Layer12), since they are not provided to the reporter.
This version of zope.testrunner is customized to list tests by just printing
all their IDs to stdout even in subunit mode. This is not really correct
and should be fixed at some point, but it simplifies Launchpad's
testrepository plumbing.

>>> sys.argv = 'test --layer 122 --list-tests -t TestNotMuch'.split()
>>> testrunner.run_internal(defaults)
tags: zope:layer:samplelayers.Layer122
test: sample1.sampletests.test122.TestNotMuch.test_1
successful: sample1.sampletests.test122.TestNotMuch.test_1
test: sample1.sampletests.test122.TestNotMuch.test_2
successful: sample1.sampletests.test122.TestNotMuch.test_2
test: sample1.sampletests.test122.TestNotMuch.test_3
successful: sample1.sampletests.test122.TestNotMuch.test_3
test: sampletests.test122.TestNotMuch.test_1
successful: sampletests.test122.TestNotMuch.test_1
test: sampletests.test122.TestNotMuch.test_2
successful: sampletests.test122.TestNotMuch.test_2
test: sampletests.test122.TestNotMuch.test_3
successful: sampletests.test122.TestNotMuch.test_3
tags: -zope:layer:samplelayers.Layer122
sample1.sampletests.test122.TestNotMuch.test_1
sample1.sampletests.test122.TestNotMuch.test_2
sample1.sampletests.test122.TestNotMuch.test_3
sampletests.test122.TestNotMuch.test_1
sampletests.test122.TestNotMuch.test_2
sampletests.test122.TestNotMuch.test_3
False


Expand Down

0 comments on commit 2a12123

Please sign in to comment.