Skip to content

test(run): isolate cloud-bootstrap tests from ambient env; add pytest dev group#544

Open
Adekunes wants to merge 2 commits into
browser-use:mainfrom
Adekunes:fix/test-run-env-isolation
Open

test(run): isolate cloud-bootstrap tests from ambient env; add pytest dev group#544
Adekunes wants to merge 2 commits into
browser-use:mainfrom
Adekunes:fix/test-run-env-isolation

Conversation

@Adekunes

@Adekunes Adekunes commented Jul 20, 2026

Copy link
Copy Markdown

What

Two small, independent test/tooling improvements to run.py's cloud-bootstrap coverage.

1. Isolate the cloud-bootstrap tests from ambient BU_* env

run.main()'s auto-bootstrap guard reads process env directly
(BROWSER_USE_API_KEY, BU_AUTOSPAWN, BU_CDP_URL, BU_CDP_WS). Any dev box
or CI runner that exports one of these leaks it into the tests:

  • test_cloud_bootstrap_on_headless_server fails on a machine with an ambient
    BU_CDP_URL (e.g. a running local Chrome debug endpoint) — it makes
    _explicit_cdp_configured() return true and silently suppresses the
    start_remote_daemon call the test asserts on.
  • The non-cloud tests (e.g. test_stdin_executes_code) don't mock
    start_remote_daemon, so a box exporting BU_AUTOSPAWN + a key would fire
    the real thing.

Add an autouse fixture that clears those four vars before each test, so every
test starts hermetic and only sets what it needs. Source logic is unchanged —
this only fixes the tests' env assumptions.

2. Add pytest to a dev dependency-group

Running the suite via uv run --with pytest pytest builds a fresh ephemeral
overlay venv on every cold uv cache (~2.8s) instead of the persistent project
env (~0.5s). Declaring pytest in the default dev group lets uv run pytest
resolve it from the synced project env, keeping repeat runs sub-second.
uv.lock is gitignored, so only pyproject.toml changes.

Testing

uv run pytest tests/unit -q → all green on top of current main.

🤖 Generated with Claude Code


Summary by cubic

Isolates cloud-bootstrap tests from ambient env vars and adds pytest to the dev dependency group to prevent flaky tests and speed up local runs.

  • Bug Fixes

    • Added an autouse fixture that clears BROWSER_USE_API_KEY, BU_AUTOSPAWN, BU_CDP_URL, and BU_CDP_WS before each test.
    • Prevents false positives in the bootstrap guard and avoids triggering real start_remote_daemon on machines with BU_AUTOSPAWN or a local CDP URL.
  • Dependencies

    • Added pytest>=8 to the dev group.
    • Allows uv run pytest to use the persistent project env for faster repeat runs.

Written for commit aa4e15a. Summary will update on new commits.

Review in cubic

Adekunes and others added 2 commits July 20, 2026 17:22
test_cloud_bootstrap_on_headless_server failed on any box that exports
BU_CDP_URL (a running local Chrome debug endpoint): run.main()'s bootstrap
guard reads process env directly, so the ambient value made
_explicit_cdp_configured() true and suppressed the start_remote_daemon call
the test asserts on.

Add an autouse fixture that clears BROWSER_USE_API_KEY, BU_AUTOSPAWN,
BU_CDP_URL and BU_CDP_WS before each test, so every test starts from a clean
slate and sets only the vars it needs. Also hardens the non-cloud tests, which
would otherwise fire the real start_remote_daemon on a box exporting
BU_AUTOSPAWN + key. Source logic was correct; only the test's env assumption
was stale.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Tests were being run via `uv run --with pytest pytest`, which layers pytest
into a fresh ephemeral overlay venv on every cold uv cache (~2.8s) instead of
the persistent project env (~0.5s). Declaring pytest in the default `dev`
group lets `uv run pytest ...` resolve it from the synced project env, so
repeat runs stay sub-second. uv.lock is gitignored, so only pyproject changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

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.

1 participant