Skip to content

Commit

Permalink
Merge pull request #556 from launchableinc/fix-parse-error-message
Browse files Browse the repository at this point in the history
Add stdout/stderr method to parse messages
  • Loading branch information
Konboi authored Apr 27, 2023
2 parents 0fabd16 + 4a18a8f commit 7f2f3e2
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 327 deletions.
46 changes: 44 additions & 2 deletions launchable/commands/record/case_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from ...testpath import FilePathNormalizer, TestPath

POSSIBLE_RESULTS = (Failure, Error, Skipped)

CaseEventType = Dict[str, str]


Expand Down Expand Up @@ -76,10 +78,50 @@ def path_canonicalizer(test_path: TestPath) -> TestPath:

return test_path

def stdout(case: TestCase) -> str:
"""
case for:
<testcase>
<system-out>...</system-out>
</testcase>
"""
if case.system_out is not None:
return case.system_out

return ""

def stderr(case: TestCase) -> str:
"""
case for:
<testcase>
<system-err>...</system-err>
</testcase>
"""
if case.system_err is not None:
return case.system_err

"""
case for:
<testcase>
<failure message="...">...</failure>
</testcase>
"""
stderr = ""
for result in case.result:
if type(result) in POSSIBLE_RESULTS:
if result.message and result.text:
stderr = stderr + result.message + "\n" + result.text
elif result.message:
stderr = stderr + result.message + "\n"
elif result.text:
stderr = stderr + result.text

return stderr

return CaseEvent.create(
path_canonicalizer(path_builder(case, suite, report_file)), case.time, status,
case._elem.attrib.get("system-out"),
case._elem.attrib.get("system-err"),
stdout(case),
stderr(case),
suite.timestamp, data)

@classmethod
Expand Down
71 changes: 70 additions & 1 deletion launchable/test_runners/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,78 @@ def parse_func(
elif outcome == "skipped":
status = CaseEvent.TEST_SKIPPED

"""example json
"longrepr": {
"reprcrash": {
"lineno": 6,
"message": "assert 1 == False",
"path": "/Users/yabuki-ryosuke/src/github.com/launchableinc/cli/tests/data/pytest/tests/test_funcs1.py"
},
"reprtraceback": {
"extraline": null,
"reprentries": [
{
"data": {
"lines": [
" def test_func2():",
"> assert 1 == False",
"E assert 1 == False"
],
"reprfileloc": {
"lineno": 6,
"message": "AssertionError",
"path": "tests/test_funcs1.py"
},
"reprfuncargs": {
"args": []
},
"reprlocals": null,
"style": "long"
},
"type": "ReprEntry"
}
],
"style": "long"
},
"sections": []
}
"""
stdout = ""
stderr = ""
longrepr = data.get("longrepr", None)
if longrepr:
message = None
reprcrash = longrepr.get("reprcrash", None)
if reprcrash:
message = reprcrash.get("message", None)

text = None
reprtraceback = longrepr.get("reprtraceback", None)
if reprtraceback:
reprentries = reprtraceback.get("reprentries", None)
if reprentries:
for r in reprentries:
d = r.get("data", None)
if d:
text = "\n".join(d.get("lines", []))

if message and text:
stderr = message + "\n" + text
elif message:
stderr = stderr + message
elif text:
stderr = stderr + text

test_path = _parse_pytest_nodeid(nodeid)
for path in test_path:
if path.get("type") == "file":
path["name"] = pathlib.Path(path["name"]).as_posix()

yield CaseEvent.create(test_path, data.get("duration", 0), status, None, None, None, None)
yield CaseEvent.create(
test_path,
data.get("duration", 0),
status,
stdout,
stderr,
None,
None)
32 changes: 25 additions & 7 deletions tests/data/ant/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@
{
"type": "case",
"testPath": [
{ "type": "class", "name": "com.launchable.HelloWorldTest" },
{ "type": "testcase", "name": "testWillAlwaysFail" }
{
"type": "class",
"name": "com.launchable.HelloWorldTest"
},
{
"type": "testcase",
"name": "testWillAlwaysFail"
}
],
"duration": 0.006,
"status": 0,
"stdout": "",
"stderr": "",
"stderr": "An error message\njunit.framework.AssertionFailedError: An error message\n\tat com.launchable.HelloWorldTest.testWillAlwaysFail(Unknown Source)\n",
"created_at": "2021-04-28T10:36:31",
"data": null
},
{
"type": "case",
"testPath": [
{ "type": "class", "name": "com.launchable.HelloWorldTest" },
{ "type": "testcase", "name": "testNothing" }
{
"type": "class",
"name": "com.launchable.HelloWorldTest"
},
{
"type": "testcase",
"name": "testNothing"
}
],
"duration": 0.0,
"status": 1,
Expand All @@ -29,8 +41,14 @@
{
"type": "case",
"testPath": [
{ "type": "class", "name": "com.launchable.library.CacheTest" },
{ "type": "testcase", "name": "testCache" }
{
"type": "class",
"name": "com.launchable.library.CacheTest"
},
{
"type": "testcase",
"name": "testCache"
}
],
"duration": 0.001,
"status": 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/data/behave/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"duration": 0.000202,
"status": 1,
"stdout": "",
"stdout": "\n\n@scenario.begin\n Scenario: run a simple test\n Given we have behave installed ... passed in 0.000s\n When we implement a test ... passed in 0.000s\n Then behave will test it for us! ... passed in 0.000s\n\n@scenario.end\n--------------------------------------------------------------------------------\n\n",
"stderr": "",
"data": null
}
Expand Down
21 changes: 15 additions & 6 deletions tests/data/ctest/record_test_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
{
"type": "case",
"testPath": [
{ "type": "testcase", "name": "FooTest.Bar" }
{
"type": "testcase",
"name": "FooTest.Bar"
}
],
"duration": 0.00555322,
"status": 0,
"stdout": "Note: Google Test filter = FooTest.Bar\n[==========] Running 1 test from 1 test suite.\n[----------] Global test environment set-up.\n[----------] 1 test from FooTest\n[ RUN ] FooTest.Bar\n/Users/ninjin/src/github.com/launchableinc/rocket-car-googletest/test_a.cpp:21: Failure\nExpected equality of these values:\n false\n true\n[ FAILED ] FooTest.Bar (0 ms)\n[----------] 1 test from FooTest (0 ms total)\n\n[----------] Global test environment tear-down\n[==========] 1 test from 1 test suite ran. (0 ms total)\n[ PASSED ] 0 tests.\n[ FAILED ] 1 test, listed below:\n[ FAILED ] FooTest.Bar\n\n 1 FAILED TEST\n",
"stderr": "",
"stderr": "Note: Google Test filter = FooTest.Bar\n[==========] Running 1 test from 1 test suite.\n[----------] Global test environment set-up.\n[----------] 1 test from FooTest\n[ RUN ] FooTest.Bar\n/Users/ninjin/src/github.com/launchableinc/rocket-car-googletest/test_a.cpp:21: Failure\nExpected equality of these values:\n false\n true\n[ FAILED ] FooTest.Bar (0 ms)\n[----------] 1 test from FooTest (0 ms total)\n\n[----------] Global test environment tear-down\n[==========] 1 test from 1 test suite ran. (0 ms total)\n[ PASSED ] 0 tests.\n[ FAILED ] 1 test, listed below:\n[ FAILED ] FooTest.Bar\n\n 1 FAILED TEST\n",
"data": null
},
{
"type": "case",
"testPath": [
{ "type": "testcase", "name": "FooTest.Baz" }
{
"type": "testcase",
"name": "FooTest.Baz"
}
],
"duration": 0.00448564,
"status": 1,
Expand All @@ -25,7 +31,10 @@
{
"type": "case",
"testPath": [
{ "type": "testcase", "name": "FooTest.Foo" }
{
"type": "testcase",
"name": "FooTest.Foo"
}
],
"duration": 0.00486448,
"status": 1,
Expand All @@ -41,10 +50,10 @@
"name": "*/ParameterizedTest.Bar/*"
}
],
"duration": 0,
"duration": 0.0,
"status": 2,
"stdout": "Note: Google Test filter = */ParameterizedTest.Bar/*\n[==========] Running 3 tests from 1 test suite.\n[----------] Global test environment set-up.\n[----------] 3 tests from IncetanceA/ParameterizedTest\n[ RUN ] IncetanceA/ParameterizedTest.Bar/0\n[ OK ] IncetanceA/ParameterizedTest.Bar/0 (0 ms)\n[ RUN ] IncetanceA/ParameterizedTest.Bar/1\n[ OK ] IncetanceA/ParameterizedTest.Bar/1 (0 ms)\n[ RUN ] IncetanceA/ParameterizedTest.Bar/2\n[ OK ] IncetanceA/ParameterizedTest.Bar/2 (0 ms)\n[----------] 3 tests from IncetanceA/ParameterizedTest (0 ms total)\n\n[----------] Global test environment tear-down\n[==========] 3 tests from 1 test suite ran. (0 ms total)\n[ PASSED ] 3 tests.\n",
"stderr": "",
"stderr": "Note: Google Test filter = */ParameterizedTest.Bar/*\n[==========] Running 3 tests from 1 test suite.\n[----------] Global test environment set-up.\n[----------] 3 tests from IncetanceA/ParameterizedTest\n[ RUN ] IncetanceA/ParameterizedTest.Bar/0\n[ OK ] IncetanceA/ParameterizedTest.Bar/0 (0 ms)\n[ RUN ] IncetanceA/ParameterizedTest.Bar/1\n[ OK ] IncetanceA/ParameterizedTest.Bar/1 (0 ms)\n[ RUN ] IncetanceA/ParameterizedTest.Bar/2\n[ OK ] IncetanceA/ParameterizedTest.Bar/2 (0 ms)\n[----------] 3 tests from IncetanceA/ParameterizedTest (0 ms total)\n\n[----------] Global test environment tear-down\n[==========] 3 tests from 1 test suite ran. (0 ms total)\n[ PASSED ] 3 tests.\n",
"data": null
}
],
Expand Down
Loading

0 comments on commit 7f2f3e2

Please sign in to comment.