Skip to content

BuiltIn: Explicitly mark arguments that are positional-only  #5025

Closed

Description

@MaxRau

Robot Framework Version: 7.0 (also occurs on 6.1.1)
Python interpreter version: 3.11.3
OS: Windows 10 and RHEL

Run Keyword and Expect Error fails when expected_error is a named argument (expected_error=thing) it will look for an error beginning with the string expected_error=

Example passing and failing TC using positional and named arg respectively

*** Test Cases ***
TestExpectErrorPositionalArg
Run Keyword And Expect Error
... REGEXP:^.abc123.$
... Fail
... msg=Error message including substring abc123 to be matched against

TestExpectErrorNamedArg
Run Keyword And Expect Error
... expected_error=REGEXP:^.abc123.$
... Fail
... msg=Error message including substring abc123 to be matched against

Error message from test2:
Expected error '**expected_error=**REGEXP:^.abc123.$' but got 'Error message including substring abc123 to be matched against'.

You can see that it is searching for a literal string beginning with expected_error= and REGEX prefix isn't considered to be at beginning of line so isn't parsed.

I think as written the _error_is_expected function doesn't handle named variables correctly.

Activity

  1. pekkaklarck commented on May 20, 2025

    @pekkaklarck
    Member

    expected_error cannot be specified as a named argument. Other Run Keyword variants have the same limitation. This needs to be documented

  2. added this to the v7.4 milestone on May 20, 2025
  3. changed the title [-]Run Keyword and Expect Error fails with named arguments[/-] [+]Document that `Run Keyword` variants do not support named arguments [/+] on May 20, 2025
  4. pekkaklarck commented on May 20, 2025

    @pekkaklarck
    Member

    Keywords executed by these keywords support named args. Mixing them with arguments used by these keywords themselves wouldn't work.

  5. pekkaklarck commented on Aug 27, 2025

    @pekkaklarck
    Member

    Normal arguments accepted by various run keyword variants are In practice positional-only. Instead of mentioning that in the documentation, it is better to explicitly mark these arguments to be positional-only. That automatically adds the information to Libdoc HTML outputs, allows IDEs to warn about using these arguments as named arguments, and so on.

  6. self-assigned this
    on Aug 27, 2025
  7. changed the title [-]Document that `Run Keyword` variants do not support named arguments [/-] [+]Mark normal arguments accepted by `Run Keyword` and its variants explicitly positional-only[/+] on Aug 27, 2025
  8. pekkaklarck commented on Aug 27, 2025

    @pekkaklarck
    Member

    The root cause is exactly the same as in #5235. When fixing that, I decided to just document the behavior with some keywords that were considered more likely to be used with named arguments. I had noticed that other keywords may be affected, but didn't consider adding a note to all their docs worth the effort.

    This particular issue demonstrates that there can be confusion also with other keywords. Adding a note to all docs would be quite a big task, but adding the positional-only marker / to signatures is luckily simpler.

  9. changed the title [-]Mark normal arguments accepted by `Run Keyword` and its variants explicitly positional-only[/-] [+]BuiltIn: Mark arguments that are positional only explicitly[/+] on Aug 27, 2025
  10. changed the title [-]BuiltIn: Mark arguments that are positional only explicitly[/-] [+]BuiltIn: Explicitly mark arguments that are positional-only [/+] on Aug 27, 2025
  11. added a commit that references this issue on Aug 27, 2025
    1494bdc
  12. pekkaklarck commented on Dec 17, 2025

    @pekkaklarck
    Member

    Making arguments explicitly positional-only caused problems when these method are used from Python. With keywords accepting *args it hasn't been in practice possible to use arguments like name=value even earlier, but there are some keywords where that syntax used to work. For example, BuiltIn().get_variable_value("${x}", default="value") used to work, but nowadays that syntax causes an error and BuiltIn().get_variable_value("${x}", "value") needs to be used instead. This is rather annoying and we need to decide how to handle. Options are:

    1. Consider the current behavior fine. Usage from Python is not that common and using "value" instead of default="value" isn't that bad.
    2. Revert the change with keywords not accepting *args. Then we should document that these keywords don't support the ´name=value` syntax when used from Python.
    3. Try to make keywords that don't accept *args to work with the name=value syntax also from Python. This would be the best solution, but it may not be easy.

    Regardless what we do, RF 7.4 release notes need to be updated so that this issue is mentioned under backwards incompatible changes.

  13. added 2 commits that reference this issue on Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions