Skip to content

Test-order-dependent failure: importlib.reload() in test_action_timeout.py corrupts Tools class identity for the rest of the pytest process #5425

Closed as not planned

Description

@axisrow

Summary

tests/ci/test_action_timeout.py::test_malformed_env_timeout_does_not_break_import calls importlib.reload(browser_use.tools.service) ten times in a row (once per malformed BROWSER_USE_ACTION_TIMEOUT_S value it checks). Each reload() rebinds browser_use.tools.service.Tools to a new class object. But Tools is already imported by value (from browser_use.tools.service import Tools) in several other modules before this test ever runs:

  • browser_use/agent/service.py
  • browser_use/beta/service.py
  • browser_use/mcp/client.py
  • browser_use/mcp/server.py
  • browser_use/integrations/gmail/actions.py
  • browser_use/__init__.py

Those modules keep pointing at whatever Tools object existed at their own import time (normally the very first, pre-reload one). The fixture's final reload() on teardown doesn't restore the original object either — it creates yet another new one. So for the rest of that pytest process, any Tools freshly imported from tools.service no longer is-matches (or isinstance-matches) the Tools object baked into agent/service.py / beta/service.py.

Reproduction

Minimal reproduction, no pytest involved:

import importlib
import browser_use.tools.service as svc
from browser_use.agent.service import Agent
import browser_use.agent.service as agent_svc

Tools_before = svc.Tools
print(Tools_before is agent_svc.Tools)   # True

importlib.reload(svc)
print(svc.Tools is Tools_before)          # False - new class object
print(agent_svc.Tools is Tools_before)    # True - agent.service still holds the OLD class
print(agent_svc.Tools is svc.Tools)       # False - desynced for the rest of the process

Observed effect

Running the full tests/ci suite (not in isolation) reliably fails two tests in tests/ci/test_beta_agent.py:

  • test_beta_agent_constructor_type_hints_match_browser_use_core_params
  • test_beta_agent_initializes_tools_and_action_models

Both fail on get_origin(...) is Tools / isinstance(agent.tools, Tools) — the classes print identically (browser_use.tools.service.Tools) but are different objects. Running tests/ci/test_beta_agent.py alone is 100% green; the failure only appears when test_action_timeout.py runs earlier in the same pytest process (default, non-xdist run order). Bisecting the file list confirms test_action_timeout.py is the sole trigger — any file set that excludes it stays green, any set that includes it (with test_beta_agent.py after it) reproduces the failure.

Fix

tests/ci/test_action_timeout.py already has the pure function it needs for this: browser_use.tools.service._parse_env_action_timeout(raw: str | None) -> float, which is what _DEFAULT_ACTION_TIMEOUT_S is computed from at import time. The test can call this function directly for each malformed value instead of reloading the whole module — no sys.modules mutation, no leaked class identity, same coverage.

PR: (linked below)

Activity

  1. jinngimk-lang commented on Aug 17, 2026

    @jinngimk-lang

    This is a great test harness changes the system under test breaker: reloading one module creates a new Tools class identity while other modules keep the old one, so later tests fail depending on order.

    AgentCI is recruiting fixture/provenance integrity cases like this. A portable fixture could snapshot imported class/module identities before and after the timeout test and require zero leaked mutation into the rest of the pytest process. If you or an external agent contribute the reduced fixture, we’ll preserve this issue as provenance and give permanent public credit/backlink in AgentCI’s Breaker/Verifier Hall of Fame + priority conversion help.

    AgentCI: https://github.com/jinngimk-lang/agentci · recognition: https://github.com/jinngimk-lang/agentci/blob/main/COMMUNITY.md

    Affiliation disclosed; no Browser Use certification claim.

  2. github-actions commented on Oct 17, 2026

    @github-actions

    👋 This issue has been automatically marked as stale because it hasn't had activity for 60 days.

    ⚡ We've made significant progress recently! Please test with the latest version of browser-use to see if this issue has been resolved. If the issue persists, please let us know by commenting below.

    To keep this issue open:

    • Add a comment explaining why this is still relevant after testing the latest version
    • Add the pinned label if this is an important long-term issue
    • Reference it in a PR if you're working on a fix

    This will be automatically closed in 14 days if no further activity occurs.

    Thanks for contributing to browser-use! 🤖 If you have questions, join our Discord.

  3. github-actions commented on Nov 1, 2026

    @github-actions

    🔒 This issue was automatically closed because it was stale for 14 days with no activity.

    Don't worry! If this issue is still relevant:

    • First, test with the latest version - we've made tons of improvements recently!
    • Reopen it if you have permissions and the issue persists
    • Create a fresh issue with updated information if the problem still exists after testing the latest version
    • Join our Discord to discuss

    We appreciate your contribution to browser-use! 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions