Test Metadata setting to set default metadata for tests
Test/task level metadata was added in #4409 / #5685 but unlike other test related settings
[Metadata] has no matching setting in the *** Settings *** section. As @pekkaklarck already mentioned in
https://github.com/robotframework/robotframework/issues/4409#issuecomment-5327524558:
While reviewing the docs I realized that
[Metadata]doesn't have a matching setting in theSettingssection similarly as other settings have. We could introduce a separateTest Metadata(andTask Metadata) setting that would specify the default metadata and[Metadata]could then add new and modify values similarly as[Tags]can modify tags set withTest Tags. [...] The only design decision I see is agreeing on syntax how to remove metadata. Probably using-Namelike you can use-tagwith tags would be best.
This issue is about this enhancement.
Syntax proposal
*** Settings ***
Test Metadata Owner QA Team
Test Metadata Priority Normal
*** Test Cases ***
Use Defaults
[Documentation] Metadata is `Owner: QA Team` and `Priority: Normal`.
No Operation
Override Test Metadata
[Documentation] Metadata is `Owner: QA Team` and `Priority: Critical`.
[Metadata] Priority Critical
No Operation
Add New Test Metadata
[Documentation] Metadata is `Owner: QA Team`, `Priority: Normal` and `Issue: 4409`.
[Metadata] Issue 4409
No Operation
Remove Test Metadata
[Documentation] Metadata is only `Priority: Normal`.
[Metadata] -Owner
No OperationTask Metadata is an alias for Test Metadata, mirroring the implementation of Test Tags/Task Tags,
Test Setup/Task Setup and others.
Like the suite level Metadata setting, Test Metadata can be used multiple times, consists of
name and value, and supports documentation formatting capabilities. It is allowed in
suite files (.robot) and in suite initialization files (__init__.robot), but not in resource files(.resource).
Metadata names are compared case-insensitively and ignoring spaces and underscores, as
robot.model.Metadata is a normalized dictionary. [Metadata] -owner therefor removes Owner.
Initialization files and precedence
Test Tags in an initialization file applies to all tests in all child suites, recursively, and
merges them additive: with Test Tags init file tags in __init__.robot and
Test Tags test file tags in tests.robot, tests get init file, tags and test file.
The lower level does not replace the parent.
Test Metadata inherits the same way, in case of a name collision, the rule is to be additive across different names and have the following precedence for the same name:
[Metadata] in the test
> Test Metadata in the suite file
> Test Metadata in the nearest __init__.robot
> Test Metadata in a parent __init__.robotAn initialization file is able to have both Metadata, which is metadata
of that directory suite itself, and Test Metadata, which is default for tests inside that suite.
Scope
In scope:
- New
Test Metadatasetting and itsTask Metadataalias, in suite files and in init files. - Recursive inheritance through initialization files, with the precedence described above.
[Metadata]adding to, overriding, and removing from those defaults.- Parsing model support: new token type and statement class, exposed via
robot.api.parsing. TestDefaultssupport so the setting works with the parser API and with init files.- Documentation and acceptance/unit tests.
Out of scope:
- Specifying metadata without the
Metadata/[Metadata]setting, e.g.[Issue] 4409(#5637). - Keyword level metadata (#5627).
- A command line option for setting default test metadata, and any
--settag/--removetagsequivalent. - A
Default Metadatacounterpart toDefault Tags, which is deprecated anyway.
Open design decisions
- Precedence on name collisions. Is the precedence rule described above what we
want? It differs from
Test Tags, which is purely additive, but a dictionary leaves no alternative. - Value on a removal row. Should
[Metadata] -Owner some valuebe an error, or should the extra value be ignored? I would make it an error, because ignoring it can hide typos. - Escaping. Is
\-Namethe way to use a literal name starting with a hyphen, consistent with\-tag? - Removing everything. Should a test be able to drop all inherited metadata, e.g. with
[Metadata] NONEor[Metadata] -*?NONEas with[Setup],[Teardown]and[Timeout], but it is problematic with e.g. a metadata name that isNONE. - Pattern removal.
[Tags]removal goes throughTagPatterns, so-tag*and-NOT a OR bwork. Should[Metadata] -Priorit*work too? I would say no initially: metadata is a dictionary with a small, known set of names, and glob support can be added later without breaking anything.
I can start working on this issue immediately, so we can try to bring this into RF 7.5, when the plan above is approved.
Source: robotframework/robotframework