Skip to content

Commit

Permalink
adjust part slicing; add newsfrag; update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyu-ms committed Oct 10, 2023
1 parent 52ec271 commit 9e96c0c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 19 deletions.
5 changes: 5 additions & 0 deletions doc/newsfragments/2626_changed.pattern_with_parts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Filtering Patterns now are easier to use with MultiTest with parts.

* Both patterns with part specified or not could be used to filter MultiTest with parts.
* Applying patterns won't cause certain testcase appear in some different part now.
* Part feature has been tuned to generate more even parts in term of number of testcases.
5 changes: 4 additions & 1 deletion testplan/testing/multitest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,18 @@ def get_test_context(self):
ctx = []
sorted_suites = self.cfg.test_sorter.sorted_testsuites(self.cfg.suites)

g_offset = 0
for suite in sorted_suites:
testcases = suite.get_testcases()

if self.cfg.part and self.cfg.part[1] > 1:
offset = len(testcases)
testcases = [
testcase
for (idx, testcase) in enumerate(testcases)
if idx % self.cfg.part[1] == self.cfg.part[0]
if (idx + g_offset) % self.cfg.part[1] == self.cfg.part[0]
]
g_offset += offset

sorted_testcases = (
testcases
Expand Down
82 changes: 66 additions & 16 deletions tests/functional/testplan/testing/multitest/test_multitest_parts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import itertools

from testplan.testing.multitest import MultiTest, testsuite, testcase

from testplan import TestplanMock
from testplan.common.utils.testing import check_report_context
from testplan.report import Status
from testplan.runners.pools.base import Pool as ThreadPool
from testplan.runners.pools.tasks import Task
from testplan.report import Status
from testplan.testing.multitest import MultiTest, testcase, testsuite


@testsuite
Expand Down Expand Up @@ -76,19 +76,69 @@ def test_multi_parts_not_merged():

assert plan.run().run is True

assert len(plan.report.entries) == 3
assert plan.report.entries[0].name == "MTest - part(0/3)"
assert plan.report.entries[1].name == "MTest - part(1/3)"
assert plan.report.entries[2].name == "MTest - part(2/3)"
assert len(plan.report.entries[0].entries) == 2 # 2 suites
assert plan.report.entries[0].entries[0].name == "Suite1"
assert plan.report.entries[0].entries[1].name == "Suite2"
assert len(plan.report.entries[0].entries[0].entries) == 1 # param group
assert plan.report.entries[0].entries[0].entries[0].name == "test_true"
assert len(plan.report.entries[0].entries[1].entries) == 1 # param group
assert plan.report.entries[0].entries[1].entries[0].name == "test_false"
assert len(plan.report.entries[0].entries[0].entries[0].entries) == 4
assert len(plan.report.entries[0].entries[1].entries[0].entries) == 1
check_report_context(
plan.report,
[
(
"MTest - part(0/3)",
[
(
"Suite1",
[
(
"test_true",
[
"test_true <val=0>",
"test_true <val=3>",
"test_true <val=6>",
"test_true <val=9>",
],
)
],
),
("Suite2", [("test_false", ["test_false <val=''>"])]),
],
),
(
"MTest - part(1/3)",
[
(
"Suite1",
[
(
"test_true",
[
"test_true <val=1>",
"test_true <val=4>",
"test_true <val=7>",
],
)
],
),
("Suite2", [("test_false", ["test_false <val=False>"])]),
],
),
(
"MTest - part(2/3)",
[
(
"Suite1",
[
(
"test_true",
[
"test_true <val=2>",
"test_true <val=5>",
"test_true <val=8>",
],
)
],
),
("Suite2", [("test_false", ["test_false <val=None>"])]),
],
),
],
)


def test_multi_parts_merged():
Expand Down
15 changes: 13 additions & 2 deletions tests/functional/testplan/testing/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def test_programmatic_filtering(filter_obj, report_ctx):
@pytest.mark.parametrize(
"filter_obj, report_ctx",
(
# Case 1, part not specified
(
filtering.Pattern("XXX:Alpha:test_one")
| filtering.Pattern("XXX:Alpha:test_two"),
Expand All @@ -205,22 +206,32 @@ def test_programmatic_filtering(filter_obj, report_ctx):
("XXX - part(1/3)", [("Alpha", ["test_two"])]),
],
),
# Case 2, part specified
(
filtering.Pattern("XXX - part(0/3):Alpha:test_one")
| filtering.Pattern("XXX - part(0/3):Beta:test_three"),
[
("XXX - part(0/3)", [("Alpha", ["test_one"])]),
],
),
# Case 3, unix filename pattern in part
(
filtering.Pattern("XXX - part([01]/3):Alpha")
filtering.Pattern("XXX - part([012]/*):Alpha")
| filtering.Pattern("XXX:Beta:test_three"),
[
("XXX - part(0/3)", [("Alpha", ["test_one"])]),
("XXX - part(1/3)", [("Alpha", ["test_two"])]),
("XXX - part(2/3)", [("Beta", ["test_three"])]),
(
"XXX - part(2/3)",
[("Alpha", ["test_three"]), ("Beta", ["test_three"])],
),
],
),
# Case 4, ill-formed part
(
filtering.Pattern("XXX - part*"),
[],
),
),
)
def test_programmatic_filtering_with_parts(filter_obj, report_ctx):
Expand Down

0 comments on commit 9e96c0c

Please sign in to comment.