Skip to content

Commit

Permalink
Merge pull request #83 from launchableinc/ST-657
Browse files Browse the repository at this point in the history
[ST-657] shippable generic test runner support
  • Loading branch information
kohsuke authored Jan 8, 2021
2 parents 698e602 + 6712741 commit 59857f2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
7 changes: 7 additions & 0 deletions launchable/commands/record/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ...utils.gzipgen import compress
from ...utils.token import parse_token
from ...utils.env_keys import REPORT_ERROR_KEY
from ...testpath import TestPathComponent


@click.group()
Expand Down Expand Up @@ -54,6 +55,12 @@ def __init__(self):
self.reports = []
self.path_builder = CaseEvent.default_path_builder(base_path)

def make_file_path_component(self, filepath) -> TestPathComponent:
"""Create a single TestPathComponent from the given file path"""
if base_path:
filepath = os.path.relpath(filepath, start=base_path)
return {"type": "file", "name": filepath}

def report(self, junit_report_file: str):
"""Add one report file by its path name"""
self.reports.append(junit_report_file)
Expand Down
49 changes: 49 additions & 0 deletions launchable/test_runners/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# The most bare-bone versions of the test runner support
#
import click
import sys
from . import launchable
from junitparser import TestCase, TestSuite
from ..testpath import TestPath


@launchable.subset
def subset(client):
# read lines as test file names
for t in sys.stdin:
client.test_path(t)
client.run()


@click.argument('reports', required=True, nargs=-1)
@launchable.record.tests
def record_tests(client, reports):
def path_builder(case: TestCase, suite: TestSuite, report_file: str) -> TestPath:
"""path builder that puts the file name first, which is consistent with the subset command"""
def find_filename():
"""look for what looks like file names from test reports"""
for e in [case, suite]:
for a in ["file","filepath"]:
filepath = e._elem.attrib.get(a)
if filepath:
return filepath
return None # failing to find a test name


filepath = find_filename()
if not filepath:
raise click.ClickException("No file name found in %s" % report_file)

# default test path in `subset` expects to have this file name
test_path = [client.make_file_path_component(filepath)]
if suite.name:
test_path.append({"type": "testsuite", "name": suite.name})
if case.name:
test_path.append({"type": "testcase", "name": case.name})
return test_path
client.path_builder = path_builder

for r in reports:
client.report(r)
client.run()
25 changes: 0 additions & 25 deletions launchable/test_runners/generic.py

This file was deleted.

0 comments on commit 59857f2

Please sign in to comment.