Skip to content

gh-148919: Make test_redirect_no_path independent of proxy environment variables - #148920

Merged
orsenthil merged 4 commits into
python:mainfrom
sendaoYan:gh-148919
Oct 28, 2026
Merged

orsenthil merged 4 commits into
python:mainfrom
sendaoYan:gh-148919

Conversation

@sendaoYan

@sendaoYan sendaoYan commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary
test.test_urllib2.HandlerTests.test_redirect_no_path can fail when proxy-related environment variables are set (for example, http_proxy / HTTP_PROXY).

This change makes the test self-contained by clearing proxy-related environment variables within the test via test.support.os_helper.EnvironmentVarGuard.

Rationale
The test is intended to verify relative redirect behavior (Location: ?query) and should not depend on external shell/network proxy configuration.

When proxy env vars are active, request targets may be sent in absolute-form (http://python.org/path) instead of origin-form (/path), which breaks the current assertion and introduces environment-dependent failures.

Changes
Update Lib/test/test_urllib2.py in test_redirect_no_path:
Add EnvironmentVarGuard
Remove proxy-related variables (lowercase and uppercase variants, including no_proxy / NO_PROXY) for the duration of the test

@bedevere-app bedevere-app Bot added awaiting review tests Tests in the Lib/test dir labels Apr 23, 2026
@bedevere-app

bedevere-app Bot commented Apr 23, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sendaoYan

Copy link
Copy Markdown
Contributor Author

Test-fix only, I think this PR should add a label 'skip news'.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Jul 25, 2026
@sendaoYan

Copy link
Copy Markdown
Contributor Author

/touch

@sendaoYan

Copy link
Copy Markdown
Contributor Author

/label remove stable

@sendaoYan

Copy link
Copy Markdown
Contributor Author

/label remove /stale

@sendaoYan

Copy link
Copy Markdown
Contributor Author

/label remove stale

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jul 31, 2026
orsenthil and others added 2 commits October 28, 2026 10:35
…y env

test_redirect_encoding uses build_opener(), which installs the default
ProxyHandler, so it failed the same way when http_proxy was set.  Move
the environment cleanup into a helper and use EnvironmentVarGuard.unset().

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

Copy link
Copy Markdown
Member

I verified this bug. The change is required in test_redirect_encoding too.

@orsenthil orsenthil added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 28, 2026
@orsenthil
orsenthil enabled auto-merge (squash) October 28, 2026 19:05
@orsenthil
orsenthil merged commit d854380 into python:main Oct 28, 2026
58 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @sendaoYan for the PR, and @orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-app

bedevere-app Bot commented Oct 28, 2026

Copy link
Copy Markdown

GH-160846 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 28, 2026
@bedevere-app

bedevere-app Bot commented Oct 28, 2026

Copy link
Copy Markdown

GH-160847 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 28, 2026
orsenthil added a commit that referenced this pull request Oct 28, 2026
…ironment variables (GH-148920) (#160846)

gh-148919: Make test_redirect_no_path independent of proxy environment variables (GH-148920)

* gh-148919: Make test_redirect_no_path independent of proxy environment variables

* gh-148919: Also make test_redirect_encoding independent of proxy env

test_redirect_encoding uses build_opener(), which installs the default
ProxyHandler, so it failed the same way when http_proxy was set.  Move
the environment cleanup into a helper and use EnvironmentVarGuard.unset().



---------
(cherry picked from commit d854380)

Co-authored-by: sendaoYan <yansendao@hygon.cn>
Co-authored-by: Senthil Kumaran <senthil@python.org>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
orsenthil added a commit that referenced this pull request Oct 28, 2026
…ironment variables (GH-148920) (#160847)

gh-148919: Make test_redirect_no_path independent of proxy environment variables (GH-148920)


test_redirect_encoding uses build_opener(), which installs the default
ProxyHandler, so it failed the same way when http_proxy was set.  Move
the environment cleanup into a helper and use EnvironmentVarGuard.unset().



---------
(cherry picked from commit d854380)

Co-authored-by: sendaoYan <yansendao@hygon.cn>
Co-authored-by: Senthil Kumaran <senthil@python.org>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants