PythonUnitTestResultParser
public
class
PythonUnitTestResultParser
extends MultiLineReceiver
java.lang.Object | ||
↳ | com.android.ddmlib.MultiLineReceiver | |
↳ | com.android.tradefed.testtype.PythonUnitTestResultParser |
Interprets the output of tests run with Python's unittest framework and translates it into calls
on a series of ITestInvocationListener
s. Output from these tests follows this EBNF
grammar:
TestReport ::= TestResult* Line TimeMetric [FailMessage*] Status. TestResult ::= string \u201c(\u201cstring\u201d)\u201d \u201c\u2026\u201d SingleStatus. FailMessage ::= EqLine \u201cERROR:\u201d string \u201c(\u201cstring\u201d)\u201d Line Traceback Line. SingleStatus ::= \u201cok\u201d | \u201cERROR\u201d. TimeMetric ::= \u201cRan\u201d integer \u201ctests in\u201d float \u201ds\u201d. Status ::= \u201cOK\u201d | \u201cFAILED (errors=\u201d int \u201c)\u201d. Traceback ::= string+.
Example output (passing): test_size (test_rangelib.RangeSetTest) ... ok test_str (test_rangelib.RangeSetTest) ... ok test_subtract (test_rangelib.RangeSetTest) ... ok test_to_string_raw (test_rangelib.RangeSetTest) ... ok test_union (test_rangelib.RangeSetTest) ... ok
---------------------------------------------------------------------- Ran 5 tests in 0.002s
OK
Example output (failed) test_size (test_rangelib.RangeSetTest) ... ERROR
====================================================================== ERROR: test_size (test_rangelib.RangeSetTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_rangelib.py", line 129, in test_rangelib raise ValueError() ValueError ---------------------------------------------------------------------- Ran 1 test in 0.001s FAILED (errors=1)
Example output with several edge cases (failed): testError (foo.testFoo) ... ERROR testExpectedFailure (foo.testFoo) ... expected failure testFail (foo.testFoo) ... FAIL testFailWithDocString (foo.testFoo) foo bar ... FAIL testOk (foo.testFoo) ... ok testOkWithDocString (foo.testFoo) foo bar ... ok testSkipped (foo.testFoo) ... skipped 'reason foo' testUnexpectedSuccess (foo.testFoo) ... unexpected success
====================================================================== ERROR: testError (foo.testFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 11, in testError self.assertEqual(2+2, 5/0) ZeroDivisionError: integer division or modulo by zero
====================================================================== FAIL: testFail (foo.testFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 8, in testFail self.assertEqual(2+2, 5) AssertionError: 4 != 5
====================================================================== FAIL: testFailWithDocString (foo.testFoo) foo bar ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 31, in testFailWithDocString self.assertEqual(2+2, 5) AssertionError: 4 != 5
---------------------------------------------------------------------- Ran 8 tests in 0.001s
FAILED (failures=2, errors=1, skipped=1, expected failures=1, unexpected successes=1)
TODO: Consider refactoring the full class, handling is quite messy right now.
Summary
Public constructors | |
---|---|
PythonUnitTestResultParser(
Create a new |
|
PythonUnitTestResultParser(
Create a new |
Public methods | |
---|---|
void
|
finalizeParser()
|
boolean
|
isCancelled()
|
void
|
processNewLines(String[] lines)
Process Python unittest output and report parsed results. |
void
|
setFinalizeWhenParsing(boolean shouldFinalize)
|
Public constructors
PythonUnitTestResultParser
public PythonUnitTestResultParser (listeners, String runName)
Create a new PythonUnitTestResultParser
that reports to the given ITestInvocationListener
s.
Parameters | |
---|---|
listeners |
|
runName |
String |
PythonUnitTestResultParser
public PythonUnitTestResultParser (listeners, String runName, includeFilters, excludeFilters)
Create a new PythonUnitTestResultParser
that reports to the given ITestInvocationListener
s, with specified include and exclude filters.
Parameters | |
---|---|
listeners |
|
runName |
String |
includeFilters |
|
excludeFilters |
|
Public methods
finalizeParser
public void finalizeParser ()
isCancelled
public boolean isCancelled ()
Returns | |
---|---|
boolean |
processNewLines
public void processNewLines (String[] lines)
Process Python unittest output and report parsed results.
This method should be called only once with the full output, unlike the base method in
MultiLineReceiver
.
Parameters | |
---|---|
lines |
String |
setFinalizeWhenParsing
public void setFinalizeWhenParsing (boolean shouldFinalize)
Parameters | |
---|---|
shouldFinalize |
boolean |