Skip to content

gh-149496: Fix MacOSTest.test_default regression when BROWSER env var is set#149579

Merged
gpshead merged 1 commit intopython:mainfrom
secengjeff:gh-149496-fix-macos-test-browser-env
May 8, 2026
Merged

gh-149496: Fix MacOSTest.test_default regression when BROWSER env var is set#149579
gpshead merged 1 commit intopython:mainfrom
secengjeff:gh-149496-fix-macos-test-browser-env

Conversation

@secengjeff
Copy link
Copy Markdown
Contributor

Summary

  • MacOSTest.test_default asserts that webbrowser.get() returns a
    MacOS instance on macOS. When BROWSER=open (or any other value)
    is set in the environment, register_standard_browsers() registers a
    GenericBrowser as the preferred browser instead, so the
    assertIsInstance check fails.
  • This is a regression introduced in Use absolute paths when invoking built-in shell commands #137586, which added MacOSTest
    and moved test_default into it from MacOSXOSAScriptTest.
    MacOSXOSAScriptTest had an identical setUp() guard added in
    test_webbrowser failure on MacOS if BROWSER set to "open" #131254 specifically to fix this same failure pattern. That guard
    was not carried over when the test was moved.
  • Fix: add setUp() to MacOSTest to unset BROWSER for the duration
    of each test, matching the pattern already established in
    MacOSXOSAScriptTest.

Test plan

  • Run python -m test test_webbrowser with BROWSER=open set — should pass
  • Run python -m test test_webbrowser with BROWSER unset — should pass

Fixes gh-149496

…var is set

MacOSTest.test_default calls webbrowser.get() and asserts it returns a
MacOS instance. When BROWSER is set in the environment (e.g. BROWSER=open,
a common macOS workaround for the old osascript-based implementation),
register_standard_browsers() registers a GenericBrowser as the preferred
browser instead, causing the assertion to fail.

This is a regression introduced in pythongh-137586, which added MacOSTest and
moved test_default into it from MacOSXOSAScriptTest. MacOSXOSAScriptTest
had an identical setUp() guard added in pythongh-131254 specifically to fix this
same failure. The guard was not carried over to MacOSTest.

Add setUp() to MacOSTest to unset BROWSER for the duration of each test,
restoring the isolation that was already established as the correct pattern
for macOS webbrowser tests.
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label May 8, 2026
@gpshead gpshead enabled auto-merge (squash) May 8, 2026 20:32
@gpshead gpshead merged commit 45c47d2 into python:main May 8, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_webbrowser failing on MacOS

2 participants