Skip to content

Accept integer maxerrorlines via the programmatic API (#5113) - #5758

Open
jaideeppyne wants to merge 2 commits into
robotframework:masterfrom
jaideeppyne:fix/maxerrorlines-integer
Open

jaideeppyne wants to merge 2 commits into
robotframework:masterfrom
jaideeppyne:fix/maxerrorlines-integer

Conversation

@jaideeppyne

Copy link
Copy Markdown

What

Fixes #5113. Passing maxerrorlines as an int through the programmatic API crashes the whole run:

import robot
robot.run('tests.robot', maxerrorlines=10)
# [ERROR] Unexpected error: AttributeError: 'int' object has no attribute 'upper'
# → rc=255, the run is aborted

Why

RobotSettings._process_max_error_lines checks the value like a string:

def _process_max_error_lines(self, value):
    if not value or value.upper() == "NONE":   # assumes str
        return None
    value = self._convert_to_integer("MaxErrorLines", value)
    ...

That's fine for the CLI, where every option arrives as a string (--maxerrorlines 30). But the programmatic entry points (robot.run(..., maxerrorlines=10), TestSuite.run(maxerrorlines=10)) pass native Python types, and an int — the natural type for a line count — hits value.upper() and raises AttributeError.

This is inconsistent with the sibling integer option MaxAssignLength (_process_max_assign_length), which accepts ints fine because it doesn't call .upper().

How

Guard the string-only "NONE" check with isinstance(value, str), so an int flows straight to _convert_to_integer:

-        if not value or value.upper() == "NONE":
+        if not value or (isinstance(value, str) and value.upper() == "NONE"):

All existing string behaviour is preserved, and invalid values (int or string, e.g. 5) still raise a clear DataError instead of AttributeError.

Verified on current master:

input before after
10 (int) ❌ AttributeError, rc=255 ✅ 10
'15' ✅ 15 ✅ 15
None ✅ None ✅ None
'NONE' ✅ None ✅ None
5 (int) ❌ AttributeError ✅ DataError

Tests

Added test_max_error_lines_accepts_integer to utest/conf/test_settings.py. It fails on master (the int case raises AttributeError) and passes with the fix; the full test_settings suite (22 tests) stays green.


Disclosure: this change was prepared with AI assistance and reviewed/verified by me before submission.

`RobotSettings` processed the `maxerrorlines` option with
`value.upper() == "NONE"`, which assumes the value is a string. That holds
for the CLI (`--maxerrorlines 30`), but the programmatic API (`robot.run(...,
maxerrorlines=10)` and `TestSuite.run(maxerrorlines=10)`) passes native Python
types. An `int` — the natural type for a line count — raised
`AttributeError: 'int' object has no attribute 'upper'` and aborted the whole
run (rc=255).

Guard the string-only check with `isinstance(value, str)` so ints are passed
through to `_convert_to_integer`, matching the sibling `MaxAssignLength`
option. Invalid values (int or string) still raise a clear `DataError`.

Adds a regression test covering int, string, None and invalid inputs.

@yangfan-yf-yf yangfan-yf-yf left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The settings conversion no longer raises AttributeError for integers, but I can still reproduce the original #5113 behavior at 20cda9e. A direct TestSuite.run() with maxerrorlines=None, 10, "NONE", or "999" leaves robot.utils.text.MAX_ERROR_LINES at 40 and returns the same 41-line truncated message in every case. The new settings test passes because it never exercises the suite execution path.

Please add a behavior-level TestSuite.run() regression and make the direct suite path apply the configured error-line limit for the duration of execution, restoring the previous global value in a finally path. The higher-level RobotFramework._execute() already performs that save/apply/restore step; TestSuite.run() currently does not.

Local validation on Windows with Python 3.12: utest/conf/test_settings.py passed (22 passed), the direct 60-line failure reproduction remained truncated for all four values above, and git diff --check passed.

Comment thread utest/conf/test_settings.py Resolved
Fixing the settings conversion was not enough. `RobotFramework._execute()`
saves `robot.utils.text.MAX_ERROR_LINES`, applies `settings.max_error_lines`
and restores the old value in a `finally` block, but `TestSuite.run()` never
did. Executing a suite directly via the programmatic API therefore always
truncated failure messages at the default 40 lines, regardless of whether
`maxerrorlines` was given as an int, a numeric string, `None` or `"NONE"`.

Move the same save/apply/restore step into `TestSuite.run()` so both entry
points behave identically. `MAX_ASSIGN_LENGTH` is handled the same way as it
has exactly the same problem. The block in `_execute()` is kept as is; the
nested save/restore is a no-op for the command line path.

Adds a behavior level regression test running a suite via `TestSuite.run()`
and verifying that the configured limit is honoured, that it can be disabled,
and that the global value is restored afterwards.

@yangfan-yf-yf yangfan-yf-yf left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I rechecked 6fd34608. The direct TestSuite.run() path now applies the configured error-line limit and restores both global limits in finally. The new behavior tests cover the default, integer and string limits, None / NONE, a high limit, and restoration after a normal run.

I also forced TestSuite.visit() to raise and verified that both globals were restored while the original exception propagated. The two affected test modules pass locally (52 passed). I do not see a remaining code blocker, so I am approving this head.

The Acceptance and Unit Actions are still waiting for repository approval and have not run; this review does not treat those hosted checks as passed.

@jaideeppyne

Copy link
Copy Markdown
Author

You're right, and thanks for digging into it — the settings fix only covered the conversion, not the execution path. I reproduced it: a direct TestSuite.run() leaves MAX_ERROR_LINES at 40 for every value, while robot.run() honours it because _execute() does the save/apply/restore and TestSuite.run() never did.

Pushed a commit that moves that step into TestSuite.run() with a finally restore (same treatment for MAX_ASSIGN_LENGTH, which had the identical gap), plus a behaviour-level test in utest/running/test_running.py that runs a suite and checks the limit is applied, can be disabled, and that the global is restored.

@pekkaklarck

Copy link
Copy Markdown
Member

Thanks for the PR! It's too late to get this into RF 7.5 and due to being busy with trying to get the release finished, I don't have time to review this now. I added the referenced issue to RF 7.6 scope to remind us to return to this when we start its development.

@jaideeppyne

Copy link
Copy Markdown
Author

No rush at all, and thanks for scoping the issue to 7.6 rather than letting it drop.

The branch will stay as it is, so there is nothing to redo when you get to it. If it has gone stale by then I will rebase it, just say the word.

Good luck with the 7.5 release.

This branch has not been deployed

No deployments
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.

maxerrorlines does not appear to work via robot.running.model.TestSuite.run

3 participants