Commit c72a8ee9 authored by kyle Ju's avatar kyle Ju Committed by Commit Bot

Fix test name issue in the expectation when only running subtests.

Subtest name being appended twice when running only failing subtests through --isolated-script-test-filter flag.

Bug: 1026134
Change-Id: Iaae4449a462d15a2ef5e859865f075843977f2ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929534
Commit-Queue: John Chen <johnchen@chromium.org>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Reviewed-by: default avatarLuke Z <lpz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723487}
parent 212af789
...@@ -115,7 +115,8 @@ def process_skip_list(skipped_tests, results, finder, port, test_path, shard): ...@@ -115,7 +115,8 @@ def process_skip_list(skipped_tests, results, finder, port, test_path, shard):
class SubtestResultRecorder(object): class SubtestResultRecorder(object):
def __init__(self, path, port): def __init__(self, path, port):
self.result = [] self.result = []
self.test_path = path self.filename, _ = port.split_webdriver_subtest_pytest_name(
path)
self.port = port self.port = port
def pytest_runtest_logreport(self, report): def pytest_runtest_logreport(self, report):
...@@ -147,11 +148,13 @@ class SubtestResultRecorder(object): ...@@ -147,11 +148,13 @@ class SubtestResultRecorder(object):
"In-test skip decorators are disallowed.") "In-test skip decorators are disallowed.")
def record(self, report, status, message=None): def record(self, report, status, message=None):
# location is a (filesystempath, lineno, domaininfo) tuple # location is a (filesystempath, lineno, domaininfo) tuple,
# https://docs.pytest.org/en/3.6.2/reference.html#_pytest.runner.TestReport.location # indicating the actual location of a test item; domaininfo is
test_name = report.location[2] # the subtest name.
subtest_name = report.location[2]
output_name = self.port.add_webdriver_subtest_suffix( output_name = self.port.add_webdriver_subtest_suffix(
self.test_path, test_name) self.filename, subtest_name)
self.result.append(WebDriverTestResult( self.result.append(WebDriverTestResult(
output_name, status, message)) output_name, status, message))
......
...@@ -1912,8 +1912,29 @@ class Port(object): ...@@ -1912,8 +1912,29 @@ class Port(object):
return test_name + Port.WEBDRIVER_SUBTEST_SEPARATOR + subtest_name return test_name + Port.WEBDRIVER_SUBTEST_SEPARATOR + subtest_name
return test_name return test_name
def add_webdriver_subtest_pytest_suffix(self, test_name, subtest_name): @staticmethod
return test_name + self.WEBDRIVER_SUBTEST_PYTEST_SEPARATOR + subtest_name def split_webdriver_subtest_pytest_name(test_name):
"""Splits a WebDriver test name in pytest format into a filename and a subtest name and
returns both of them. E.g.
test.py::foo.html -> (test.py, foo.html)
test.py -> (test.py, None)
"""
names_after_split = test_name.split(
Port.WEBDRIVER_SUBTEST_PYTEST_SEPARATOR)
assert len(names_after_split) <= 2, "%s has a length greater than 2 after split by ::" % (
test_name)
if len(names_after_split) == 1:
return (names_after_split[0], None)
return (names_after_split[0], names_after_split[1])
@staticmethod
def add_webdriver_subtest_pytest_suffix(test_name, subtest_name):
if subtest_name is None:
return test_name
return test_name + Port.WEBDRIVER_SUBTEST_PYTEST_SEPARATOR + subtest_name
class VirtualTestSuite(object): class VirtualTestSuite(object):
......
...@@ -1163,6 +1163,16 @@ class PortTest(LoggingTestCase): ...@@ -1163,6 +1163,16 @@ class PortTest(LoggingTestCase):
Port.split_webdriver_test_name("tests/accept_alert/accept.py"), Port.split_webdriver_test_name("tests/accept_alert/accept.py"),
("tests/accept_alert/accept.py", None)) ("tests/accept_alert/accept.py", None))
def test_split_webdriver_subtest_pytest_name(self):
self.assertEqual(
Port.split_webdriver_subtest_pytest_name(
"tests/accept_alert/accept.py::foo"),
("tests/accept_alert/accept.py", "foo"))
self.assertEqual(
Port.split_webdriver_subtest_pytest_name(
"tests/accept_alert/accept.py"),
("tests/accept_alert/accept.py", None))
def test_add_webdriver_subtest_suffix(self): def test_add_webdriver_subtest_suffix(self):
self.assertEqual( self.assertEqual(
Port.add_webdriver_subtest_suffix("abd", "bar"), "abd>>bar") Port.add_webdriver_subtest_suffix("abd", "bar"), "abd>>bar")
...@@ -1170,11 +1180,10 @@ class PortTest(LoggingTestCase): ...@@ -1170,11 +1180,10 @@ class PortTest(LoggingTestCase):
Port.add_webdriver_subtest_suffix("abd", None), "abd") Port.add_webdriver_subtest_suffix("abd", None), "abd")
def test_add_webdriver_subtest_pytest_suffix(self): def test_add_webdriver_subtest_pytest_suffix(self):
port = self.make_port()
wb_test_name = "abd" wb_test_name = "abd"
sub_test_name = "bar" sub_test_name = "bar"
full_webdriver_name = port.add_webdriver_subtest_pytest_suffix( full_webdriver_name = Port.add_webdriver_subtest_pytest_suffix(
wb_test_name, sub_test_name) wb_test_name, sub_test_name)
self.assertEqual(full_webdriver_name, "abd::bar") self.assertEqual(full_webdriver_name, "abd::bar")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment