8000 Requite `--suite parent.suite` to match the full suite name · robotframework/robotframework@241bac5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 241bac5

Browse files
committed
Requite --suite parent.suite to match the full suite name
Fixes #4720.
1 parent af71a9a commit 241bac5

File tree

7 files changed

+36
-54
lines changed

7 files changed

+36
-54
lines changed

atest/robot/core/filter_by_names.robot

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ Parent suite init files are processed
7878
Should Contain Tests ${SUITE} Test From Sub Suite 4
7979
Should Not Contain Tests ${SUITE} SubSuite3 First SubSuite3 Second
8080

81-
--suite with end of long name
82-
Run Suites --suite Subsuites.Sub?
83-
Should Contain Suites ${SUITE} Subsuites
84-
Should Contain Tests ${SUITE} SubSuite1 First SubSuite2 First
81+
--suite matching end of long name is not enough anymore
82+
[Documentation] This was supported until RF 7.0.
83+
Run Failing Test
84+
... Suite 'Suites' contains no tests in suite 'Subsuites.Sub?'.
85+
... --suite Subsuites.Sub? ${SUITE DIR}
8586

8687
--suite with long name when executing multiple suites
8788
Run Suites -s "Suite With Prefix & Subsuites.Subsuites.Sub1" misc/suites/01__suite_with_prefix misc/suites/subsuites
@@ -129,7 +130,7 @@ Parent suite init files are processed
129130
Should Contain Tests ${SUITE} SubSuite1 First
130131

131132
--suite with long name and other filters
132-
Run Suites --suite suites.fourth --suite tsuite1 -s Subsuites.Sub1 --test *first* --exclude none
133+
Run Suites --suite suites.fourth --suite tsuite1 -s *.Subsuites.Sub1 --test *first* --exclude none
133134
Should Contain Suites ${SUITE} Fourth Subsuites Tsuite1
134135
Should Contain Tests ${SUITE} Suite4 First Suite1 First SubSuite1 First
135136

atest/robot/rebot/filter_by_names.robot

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ ${INPUT FILE} %{TEMPDIR}${/}robot-test-file.xml
5151
Should Contain Suites ${SUITE} Suites
5252
Should Contain Suites ${SUITE.suites[0].suites[0]} Sub1 Sub2
5353

54-
--suite with end of long name
55-
Run And Check Suites --suite suites.subsuites Subsuites
56-
Should Contain Suites ${SUITE} Suites
57-
Should Contain Suites ${SUITE.suites[0].suites[0]} Sub1 Sub2
54+
--suite matching end of long name is not enough anymore
55+
[Documentation] This was supported until RF 7.0.
56+
Failing Rebot
57+
... Suite 'Root' contains no tests in suite 'suites.subsuites'.
58+
... --suite suites.subsuites ${INPUT FILE}
5859

5960
--suite not matching
6061
Failing Rebot

doc/userguide/src/ExecutingTestCases/ConfiguringExecution.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ with a suite name::
175175

176176
Notice that when the given name includes a suite name, it must match the whole
177177
suite name starting from the root suite. Using a wildcard as in the last example
178-
above allows matching suites anywhere.
178+
above allows matching tests with a parent suite anywhere.
179179

180180
Using the :option:`--test` option is convenient when only a few tests needs
181181
to be selected. A common use case is running just the test that is currently
@@ -198,13 +198,17 @@ name::
198198
--suite Example # Match only suites with name 'Example'.
199199
--suite example* # Match suites starting with 'example'.
200200
--suite first --suite second # Match suites with name 'first' or 'second'.
201-
--suite parent.child # Match suite 'child' in suite 'parent'.
201+
--suite root.child # Match suite 'child' in root suite 'root'.
202+
--suite *.parent.child # Match suite 'child' with parent 'parent' anywhere.
202203

203-
Unlike with :option:`--test`, the name does not need to match the whole
204-
suite name, starting from the root suite, when the name contains a parent
205-
suite name. This behavior `will be changed`__ in the future and should not be relied
206-
upon. It is recommended to use the full name like `--suite root.parent.child`
207-
or `--suite *.parent.child`.
204+
If the name contains a parent suite name, it must match the whole suite name
205+
the same way as with :option:`--test`. Using a wildcard as in the last example
206+
above allows matching suites with a parent suite anywhere.
207+
208+
.. note:: Prior to Robot Framework 7.0, :option:`--suite` with a parent suite
209+
did not need to match the whole suite name. For example, `parent.child`
210+
would match suite `child` with parent `parent` anywhere. The name must
211+
be prefixed with a wildcard if this behavior is desired nowadays.
208212

209213
If both :option:`--suite` and :option:`--test` options are used, only the
210214
specified tests in specified suites are selected::
@@ -231,11 +235,10 @@ on higher level are not executed::
231235
Prior to Robot Framework 6.1, files not matching the :option:`--suite` option
232236
were not parsed at all for performance reasons. This optimization was not
233237
possible anymore after suites got a new :setting:`Name` setting that can override
234-
the default suite name got from the file or directory name. New
238+
the default suite name that is got from the file or directory name. New
235239
:option:`--parseinclude` option has been added to `explicitly select which
236240
files are parsed`__ if this kind of parsing optimization is needed.
237241

238-
__ https://github.com/robotframework/robotframework/issues/4720
239242
__ https://github.com/robotframework/robotframework/issues/4721
240243
__ `Selecting files by name or path`_
241244

src/robot/model/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from .message import Message, MessageLevel, Messages
3535
from .modelobject import DataDict, ModelObject
3636
from .modifier import ModelModifier
37-
from .namepatterns import SuiteNamePatterns, TestNamePatterns
3837
from .statistics import Statistics
3938
from .tags import Tags, TagPattern, TagPatterns
4039
from .testcase import TestCase, TestCases

src/robot/model/filter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from robot.utils import setter
1919

2020
from .tags import TagPatterns
21-
from .namepatterns import SuiteNamePatterns, TestNamePatterns
21+
from .namepatterns import NamePatterns
2222
from .visitor import SuiteVisitor
2323

2424
if TYPE_CHECKING:
@@ -46,8 +46,8 @@ def visit_keyword(self, keyword: 'Keyword'):
4646
class Filter(EmptySuiteRemover):
4747

4848
def __init__(self,
49-
include_suites: 'SuiteNamePatterns|Sequence[str]|None' = None,
50-
include_tests: 'TestNamePatterns|Sequence[str]|None' = None,
49+
include_suites: 'NamePatterns|Sequence[str]|None' = None,
50+
include_tests: 'NamePatterns|Sequence[str]|None' = None,
5151
include_tags: 'TagPatterns|Sequence[str]|None' = None,
5252
exclude_tags: 'TagPatterns|Sequence[str]|None' = None):
5353
super().__init__()
@@ -57,12 +57,12 @@ def __init__(self,
5757
self.exclude_tags = exclude_tags
5858

5959
@setter
60-
def include_suites(self, suites) -> 'SuiteNamePatterns|None':
61-
return self._patterns_or_none(suites, SuiteNamePatterns)
60+
def include_suites(self, suites) -> 'NamePatterns|None':
61+
return self._patterns_or_none(suites, NamePatterns)
6262

6363
@setter
64-
def include_tests(self, tests) -> 'TestNamePatterns|None':
65-
return self._patterns_or_none(tests, TestNamePatterns)
64+
def include_tests(self, tests) -> 'NamePatterns|None':
65+
return self._patterns_or_none(tests, NamePatterns)
6666

6767
@setter
6868
def include_tags(self, tags) -> 'TagPatterns|None':

src/robot/model/namepatterns.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,12 @@ def __init__(self, patterns: Sequence[str] = (), ignore: Sequence[str] = '_'):
2424
self.matcher = MultiMatcher(patterns, ignore)
2525

2626
def match(self, name: str, longname: 'str|None' = None) -> bool:
27-
return bool(self._match(name) or
28-
longname and self._match_longname(longname))
29-
30-
def _match(self, name: str) -> bool:
31-
return self.matcher.match(name)
32-
33-
def _match_longname(self, name: str) -> bool:
34-
raise NotImplementedError
27+
match = self.matcher.match
28+
return bool(match(name) or longname and match(longname))
3529

3630
def __bool__(self) -> bool:
3731
return bool(self.matcher)
3832

3933
def __iter__(self) -> Iterator[str]:
4034
for matcher in self.matcher:
4135
yield matcher.pattern
42-
43-
44-
class SuiteNamePatterns(NamePatterns):
45-
46-
def _match_longname(self, name):
47-
while '.' in name:
48-
if self._match(name):
49-
return True
50-
name = name.split('.', 1)[1]
51-
return False
52-
53-
54-
class TestNamePatterns(NamePatterns):
55-
56-
def _match_longname(self, name):
57-
return self._match(name)

utest/model/test_filter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import unittest
22

3-
from robot.utils.asserts import assert_equal
43
from robot.model import TestSuite
54
from robot.model.filter import Filter
5+
from robot.utils.asserts import assert_equal
66

77

88
class FilterBaseTest(unittest.TestCase):
@@ -146,11 +146,11 @@ def test_reuse_filter(self):
146146
self._test(filter, [], ['t1'])
147147
self._test(filter, [], ['t1'])
148148

149-
def test_parent_name(self):
149+
def test_longname(self):
150150
self._test(Filter(include_suites=['s1.s21.s31']), ['t1', 't2', 't3'], [])
151-
self._test(Filter(include_suites=['s2?.s31']), ['t1', 't2', 't3'], [])
151+
self._test(Filter(include_suites=['*.s2?.s31']), ['t1', 't2', 't3'], [])
152152
self._test(Filter(include_suites=['*.s22']), [], ['t1'])
153-
self._test(Filter(include_suites=['xxx.s22']), [], [])
153+
self._test(Filter(include_suites=['nonex.s22']), [], [])
154154

155155
def test_normalization(self):
156156
self._test(Filter(include_suites=['_S 2 2_', 'xxx']), [], ['t1'])

0 commit comments

Comments
 (0)
0