Skip to content

Unit test fails under Python 3.13 #5035

@fedepell

Description

@fedepell

In Fedora we have RobotFramework tests running for upcoming Fedora 41 using Python 3.13.03 in a side tag.
While running the unit tests (version 7.0) I have a new failure in utils:

FAIL: test_remove_entries_with_lambda_and_multiple_entries
(test_error.TestRemoveRobotEntriesFromTraceback.test_remove_entries_with_lambda_and_multiple_entries)
----------------------------------------------------------------------
======================================================================
FAIL: test_remove_entries_with_lambda_and_multiple_entries (test_error.TestRemoveRobotEntriesFromTraceback.test_remove_entries_with_lambda_and_multiple_entries)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/robotframework-7.0/utest/utils/test_error.py", line 107, in test_remove_entries_with_lambda_and_multiple_entries
            self._verify_traceback(r'''
            ~~~~~~~~~~~~~~~~~~~~~~^^^^^
    Traceback \(most recent call last\):
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        1/0
        ^^^
    '''.strip(), assert_raises, AssertionError, raising_lambda)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/robotframework-7.0/utest/utils/test_error.py", line 133, in _verify_traceback
    raise AssertionError('\nExpected:\n%s\n\nActual:\n%s' % (expected, tb))
AssertionError: 
Expected:
Traceback \(most recent call last\):
  File ".*", line \d+, in <lambda.*>
    raising_lambda = lambda: raises\(\)
  File ".*", line \d+, in raises
    1/0

Actual:
Traceback (most recent call last):
  File "/builddir/build/BUILD/robotframework-7.0/utest/utils/test_error.py", line 106, in <lambda>
    raising_lambda = lambda: raises()
                             ~~~~~~^^
  File "/builddir/build/BUILD/robotframework-7.0/utest/utils/test_error.py", line 105, in raises
    1/0
    ~^~
ZeroDivisionError: division by zero

----------------------------------------------------------------------
Ran 635 tests in 0.577s

FAILED (failures=1)

Looking at the output and playing a bit around the solution to me looks like changing the test filter (line in test_error.py) from:

        # Remove lines indicating error location with `^^^^` used by Python 3.11+.
        tb = '\n'.join(line for line in tb.splitlines() if line.strip('^ '))

To:

        # Remove lines indicating error location with `^^^^` used by Python 3.11+ and `~~~~^` variants in Python 3.13+.
        tb = '\n'.join(line for line in tb.splitlines() if line.strip('^~ '))

Which filters also the error indicators with ~ that seem to be new.

This makes the test pass, I hope/believe without breaking in previous versions.

If the proposal makes sense I can of course open a MR!

Thanks!
F.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions