Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lists Should Be Equals Fails but status is PASS #5088

Open
Matbellara opened this issue Mar 22, 2024 · 1 comment
Open

Lists Should Be Equals Fails but status is PASS #5088

Matbellara opened this issue Mar 22, 2024 · 1 comment

Comments

@Matbellara
Copy link

Hi,

I have a wrong usage of Lists Should Be Equal that leads to a false positive.

While comparing 2 dictionaries instead of 2 lists the assertion failed but the KWD status is PASS.

image

To reproduce the fail:

STATUS is PASSED but expected is FAIL

*** Settings ***
Library    Collections
*** Variables ***
&{expectedDict}    nome=mario  cognome=super


*** Test Cases ***
testing kwd
    Log Dictionary    ${expectedDict}
    Should Be True    isinstance($expectedDict, dict)
    Lists Should Be Equal    ${expectedDict}    ${expectedDict}

Name: robotframework
Version: 7.0

Please note that with 2 lists the KWD behavior is correct as you can tests via

testing lists - OK scenario
    Lists Should Be Equal    ${{[1,2,3]}}    ${{[1,2,3]}}

testing lists - KO scenario
    ${status}    Run Keyword And Return Status    Lists Should Be Equal    ${{[1,2,3]}}    ${{[1,2]}}
    Should Be True    not $status
@pekkaklarck
Copy link
Member

The reason is that because dictionaries can be iterated, iteration yields keys, Robot considers them list-like and they are generally allowed to be used as lists. Also this example passes:

Lists should be equal    ${{{'a': 1, 'b': 2}}}    ${{['a', 'b']}}

Allowing dictionaries to be used as lists is often convenient, but it's somewhat questionable should list related keywords in Collections support them. It's possible that someone has used this functionality, for example, for validating that a dictionary has correct keys, and changing the behavior would then cause backwards compatibility issues. On the other hand, supporting dicts in this context can cause false positives and in general cause confusion. If others agree, I'd be fine with the behavior being changed, but it would be best to do it in a major release.

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

No branches or pull requests

2 participants