8000 Deprecate using '-tag' syntax with [Tags]. #4380 · robotframework/robotframework@f387f49 · GitHub
[go: up one dir, main page]

Skip to content

Commit f387f49

Browse files
committed
Deprecate using '-tag' syntax with [Tags]. #4380
Documentation still missing.
1 parent a8b980d commit f387f49

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

atest/resources/atest_resource.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ Reset PYTHONPATH
349349

350350
Error in file
351351
[Arguments] ${index} ${path} ${lineno} @{message} ${traceback}=
352-
... ${stacktrace}= ${pattern}=True
352+
... ${stacktrace}= ${pattern}=True ${level}=ERROR
353353
${path} = Join Path ${DATADIR} ${path}
354354
${message} = Catenate @{message}
355355
${error} = Set Variable Error in file '${path}' on line ${lineno}: ${message}
@@ -359,7 +359,7 @@ Error in file
359359
${error} = Set Variable If $stacktrace
360360
... ${error}\n*${stacktrace}*
361361
... ${error}
362-
Check Log Message ${ERRORS}[${index}] ${error} level=ERROR pattern=${pattern}
362+
Check Log Message ${ERRORS}[${index}] ${error} level=${level} pattern=${pattern}
363363

364364
Error in library
365365
[Arguments] ${name} @{message} ${pattern}=False ${index}=0

atest/robot/tags/-tag_syntax.robot

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
*** Settings ***
2+
Suite Setup Run Tests ${EMPTY} tags/-tag_syntax.robot
3+
Resource atest_resource.robot
4+
5+
*** Test Cases ***
6+
Deprecation warning with test
7+
Check Test Tags Deprecation warning -literal-with-force -warn-with-test
8+
Check Deprecation Warning 0 tags/-tag_syntax.robot 11 -warn-with-test
9+
10+
Deprecation warning with keyword
11+
${tc} = Check Test Case Deprecation warning
12+
Check Keyword Data ${tc.kws[0]} Keyword tags=-warn-with-keyword
13+
Check Deprecation Warning 1 tags/-tag_syntax.robot 25 -warn-with-keyword
14+
15+
Deprecation warning with keyword in resource
16+
${tc} = Check Test Case Deprecation warning
17+
Check Keyword Data ${tc.kws[1]} -tag_syntax.Keyword In Resource tags=-warn-with-keyword-in-resource
18+
Check Deprecation Warning 2 tags/-tag_syntax.resource 3 -warn-with-keyword-in-resource
19+
20+
No deprecation warning from Settings, when escaped, or with variables
21+
Length Should Be ${ERRORS} 3
22+
23+
Escaped
24+
Check Test Tags ${TESTNAME} -literal-escaped -literal-with-force
25+
26+
Variable
27+
Check Test Tags ${TESTNAME} -literal-with-force -literal-with-variable
28+
29+
*** Keywords ***
30+
Check Deprecation Warning
31+
[Arguments] ${index} ${source} ${lineno} ${tag}
32+
Error in file ${index} ${source} ${lineno}
33+
... Settings tags starting with a hyphen using the '[Tags]' setting is deprecated.
34+
... In Robot Framework 5.2 this syntax will be used for removing tags.
35+
... Escape '${tag}' like '\\${tag}' to use the literal value and to avoid this warning.
36+
... level=WARN pattern=False
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*** Keywords ***
2+
Keyword In Resource
3+
[Tags] -warn-with-keyword-in-resource
4+
No Operation

atest/testdata/tags/-tag_syntax.robot

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*** Settings ***
2+
Force Tags -literal-with-force
3+
Default Tags -literal-with-default
4+
Resource -tag_syntax.resource
5+
6+
*** Variables ***
7+
${TAG} -literal-with-variable
8+
9+
*** Test Cases ***
10+
Deprecation warning
11+
[Tags] -warn-with-test
12+
Keyword
13+
Keyword In Resource
14+
15+
Escaped
16+
[Tags] \-literal-escaped
17+
No Operation
18+
19+
Variable
20+
[Tags] ${TAG}
21+
No Operation
22+
23+
*** Keywords ***
24+
Keyword
25+
[Tags] -warn-with-keyword
26+
No Operation

src/robot/running/builder/transformers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from ast import NodeVisitor
1717

18+
from robot.output import LOGGER
1819
from robot.variables import VariableIterator
1920

2021
from .testsettings import TestSettings
@@ -218,6 +219,7 @@ def visit_Timeout(self, node):
218219
self.settings.timeout = node.value
219220

220221
def visit_Tags(self, node):
222+
deprecate_tags_starting_with_hyphen(node, self.suite.source)
221223
self.settings.tags = node.values
222224

223225
def visit_Template(self, node):
@@ -264,6 +266,7 @@ def visit_Arguments(self, node):
264266
% format_error(node.errors))
265267

266268
def visit_Tags(self, node):
269+
deprecate_tags_starting_with_hyphen(node, self.resource.source)
267270
self.kw.tags = node.values
268271

269272
def visit_Return(self, node):
@@ -550,3 +553,15 @@ def format_error(errors):
550553
if len(errors) == 1:
551554
return errors[0]
552555
return '\n- '.join(('Multiple errors:',) + errors)
556+
557+
558+
def deprecate_tags_starting_with_hyphen(node, source):
559+
for tag in node.values:
560+
if tag.startswith('-'):
561+
LOGGER.warn(
562+
f"Error in file '{source}' on line {node.lineno}: "
563+
f"Settings tags starting with a hyphen using the '[Tags]' setting "
564+
f"is deprecated. In Robot Framework 5.2 this syntax will be used "
565+
f"for removing tags. Escape '{tag}' like '\\{tag}' to use the "
566+
f"literal value and to avoid this warning."
567+
)

0 commit comments

Comments
 (0)
0