Skip to content

TR-22028: Priority tag mapping for Robot Parser - #468

Open
acuanico-tr-galt wants to merge 4 commits into
feature/TR-22030from
feature/TR-22028
Open

acuanico-tr-galt wants to merge 4 commits into
feature/TR-22030from
feature/TR-22028

Conversation

@acuanico-tr-galt

Copy link
Copy Markdown
Contributor

Solution description

Automatically map Robot Framework priority: tags to TestRail priority_id values when importing results via parse_robot. Test tags matching priority:critical, priority:high, priority:medium, or priority:low (case-insensitive) are parsed and converted to the corresponding TestRail priority_id, using a default mapping (critical=4, high=3, medium=2, low=1).

NEW flag: --priority-tag-mapping CLI option (repeatable, level:id format, e.g. --priority-tag-mapping critical:5 --priority-tag-mapping low:1) lets users override or extend the default mapping per-run, without needing to specify every level — unspecified levels keep their defaults, and new custom level names can be added.

Changes

  • trcli/data_classes/data_parsers.py: New PriorityTagMappingParser class with DEFAULT_MAPPING (critical=4, high=3, medium=2, low=1) and resolve_mapping() for parsing/validating --priority-tag-mapping CLI values (partial-override semantics).
  • trcli/commands/cmd_parse_robot.py: New --priority-tag-mapping option (Robot-specific, multiple, level:id format).
  • trcli/cli.py: New Environment.priority_tag_mapping property/setter following the existing case_fields/result_fields pattern.
  • trcli/readers/robot_xml.py: RobotParser now resolves priority: tags (case-insensitive) to a priority_id case field via new _priority_id_from_tags() helper, with explicit - testrail_case_field: priority_id:X doc directives always taking precedence, and graceful (non-fatal, verbose-logged) handling of unrecognized/duplicate tags.

Potential impacts

None.

Steps to test

See updated README: 216 - 259

PR Tasks

  • PR reference added to issue
  • README updated
  • Unit tests added/updated

@acuanico-tr-galt acuanico-tr-galt changed the title TR-22028: Priority tag papping for Robot Parser TR-22028: Priority tag mapping for Robot Parser Sep 23, 2026
return resolved, "Invalid --priority-tag-mapping entry: level name cannot be empty"
try:
resolved[level_key] = int(str(priority_id).strip())
except (ValueError, TypeError):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved is mutated inside this loop. If the first entry succeeds (critical:5 → resolved["critical"] = 5) and a later entry fails (high:not_a_number), the function returns the partially-mutated resolved dict alongside the error. The caller gets back {"critical": 5, "high": 3, ...} — not the clean defaults. The test_entry_without_colon_is_rejected test asserts mapping == DEFAULT_MAPPING, but only works because that test uses a single-entry list. A two-entry test like ["critical:5", "high:not_a_number"] would break that invariant. The fix is simple: return a fresh dict(PriorityTagMappingParser.DEFAULT_MAPPING) instead of the dirty resolved in the error paths inside the second loop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved. Both error paths in second loop now return proper dict(PriorityTagMappingParser.DEFAULT_MAPPING) instead of partially mutated resolved dict.

Comment thread trcli/commands/cmd_parse_robot.py Outdated
@click.option(
"--priority-tag-mapping",
multiple=True,
metavar="",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With metavar="", running trcli parse_robot --help will show --priority-tag-mapping with no hint of what format to pass. The user has no idea it takes LEVEL:ID. Use metavar="LEVEL:ID" (or metavar="TEXT") to give them a signal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants