Repository navigation
test: avoid module reload state leakage - #6129
Open
daleselaji-dev wants to merge 1 commit into
Open
daleselaji-dev wants to merge 1 commit into
daleselaji-dev wants to merge 1 commit into
Conversation
daleselaji-dev
marked this pull request as ready for review
October 18, 2026 12:37
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/ci/test_action_timeout.py">
<violation number="1" location="tests/ci/test_action_timeout.py:147">
P3: This test now covers only the pure parser, so nothing checks that `BROWSER_USE_ACTION_TIMEOUT_S` actually feeds `_DEFAULT_ACTION_TIMEOUT_S` at import. A regression in the `os.getenv` call at module level would go unnoticed. Consider a subprocess-based check that imports the module with the env var set, which avoids the in-process reload that caused the state leak.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| Reloading recreates the module's ``Tools`` class while other modules retain the | ||
| original class object, making later type-identity tests depend on test order. | ||
| """ | ||
| from browser_use.tools.service import _parse_env_action_timeout |
Contributor
There was a problem hiding this comment.
P3: This test now covers only the pure parser, so nothing checks that BROWSER_USE_ACTION_TIMEOUT_S actually feeds _DEFAULT_ACTION_TIMEOUT_S at import. A regression in the os.getenv call at module level would go unnoticed. Consider a subprocess-based check that imports the module with the env var set, which avoids the in-process reload that caused the state leak.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/ci/test_action_timeout.py, line 147:
<comment>This test now covers only the pure parser, so nothing checks that `BROWSER_USE_ACTION_TIMEOUT_S` actually feeds `_DEFAULT_ACTION_TIMEOUT_S` at import. A regression in the `os.getenv` call at module level would go unnoticed. Consider a subprocess-based check that imports the module with the env var set, which avoids the in-process reload that caused the state leak.</comment>
<file context>
@@ -132,45 +132,23 @@ def test_default_action_timeout_accommodates_extract_action():
+ Reloading recreates the module's ``Tools`` class while other modules retain the
+ original class object, making later type-identity tests depend on test order.
+ """
+ from browser_use.tools.service import _parse_env_action_timeout
bad_values = ('', 'not-a-number', 'abc', 'nan', 'NaN', 'inf', '-inf', '0', '-5')
</file context>
sun04222
added a commit
to sun04222/browser-use
that referenced
this pull request
Oct 23, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
tests/ci/test_action_timeout.py::test_malformed_env_timeout_does_not_break_importreloadsbrowser_use.tools.servicerepeatedly. Later tests that compare the sharedToolsclass by identity can then fail even though the class names are identical.Root Cause
importlib.reload()creates a newToolsclass object. Modules that importedToolsby value before the reload retain the original object, soisandisinstancechecks become order-dependent for the remainder of the pytest process.Solution
Exercise the existing pure
_parse_env_action_timeout()helper directly instead of reloading the service module. This preserves coverage of invalid and valid timeout values without mutating module/class identity.Changes
tests/ci/test_action_timeout.py.45second value.Testing
uv run pytest tests/ci/test_action_timeout.py tests/ci/test_beta_agent.py -qreproduced the issue:test_beta_agent_constructor_type_hints_match_browser_use_core_paramsfailed with two distinctToolsclass objects.uv run pytest tests/ci/test_action_timeout.py -q— 5 passed.uv run pytest tests/ci/test_beta_agent.py::test_beta_agent_constructor_type_hints_match_browser_use_core_params -q— 1 passed.uv run ruff check tests/ci/test_action_timeout.py tests/ci/test_beta_agent.py— passed.uv run ruff format --check tests/ci/test_action_timeout.py tests/ci/test_beta_agent.py— passed.uv run pyright tests/ci/test_action_timeout.py tests/ci/test_beta_agent.py— 0 errors, 0 warnings.uv run pre-commit run --files tests/ci/test_action_timeout.py— passed.git diff --check— passed.uv run pytest tests/ci -qwithPYTHONUTF8=1 PYTHONIOENCODING=utf-8: 87 passed, 3 skipped, then stopped at the unrelated existing Windows path assertion intests/ci/infrastructure/test_config.py::TestLazyConfig::test_path_configuration(C:\Users\ACE\.cachevs expected/.cache). Without UTF-8, the same suite first stopped after 15 passes on an unrelated GBK console encoding error intests/ci/browser/test_cross_origin_click.py.Compatibility/Risk
This is test-only. It removes process-wide module mutation and keeps the timeout parser assertions unchanged in intent. No runtime behavior or public API changes.
Notes for Reviewer
The targeted baseline failure is order-dependent: running the timeout test before the beta type-hint test reproduces the class identity mismatch; the focused regression passes after this change. The full CI suite remains locally unverified beyond the unrelated Windows/environment failures documented above.
Linked Issue
Fixes #5425
AI Disclosure
AI assistance was used for diagnosis, implementation, and local validation; the change is limited to the test harness and the results above are from this checkout.
Summary by cubic
Fixes test pollution caused by reloading
browser_use.tools.service, which recreates theToolsclass and makes later identity-based tests order-dependent.test_action_timeout.pywith direct calls to the existing_parse_env_action_timeout()helper.45-second value.Written for commit 03969ad. Summary will update on new commits.