Repository navigation
Accept integer maxerrorlines via the programmatic API (#5113) - #5758
jaideeppyne wants to merge 2 commits into
Conversation
`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
left a comment
There was a problem hiding this comment.
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.
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
left a comment
There was a problem hiding this comment.
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.
|
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 Pushed a commit that moves that step into |
|
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. |
|
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. |
What
Fixes #5113. Passing
maxerrorlinesas an int through the programmatic API crashes the whole run:Why
RobotSettings._process_max_error_lineschecks the value like a string: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 anint— the natural type for a line count — hitsvalue.upper()and raisesAttributeError.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 withisinstance(value, str), so an int flows straight to_convert_to_integer:All existing string behaviour is preserved, and invalid values (int or string, e.g.
5) still raise a clearDataErrorinstead ofAttributeError.Verified on current
master:10(int)10'15'1515NoneNoneNone'NONE'NoneNone5(int)DataErrorTests
Added
test_max_error_lines_accepts_integertoutest/conf/test_settings.py. It fails onmaster(theintcase raisesAttributeError) and passes with the fix; the fulltest_settingssuite (22 tests) stays green.Disclosure: this change was prepared with AI assistance and reviewed/verified by me before submission.