Repository navigation
gh-148919: Make test_redirect_no_path independent of proxy environment variables - #148920
Conversation
…ronment variables
|
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 |
|
Test-fix only, I think this PR should add a label 'skip news'. |
|
This PR is stale because it has been open for 90 days with no activity. |
|
/touch |
|
/label remove stable |
|
/label remove /stale |
|
/label remove stale |
…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 <[email protected]>
|
I verified this bug. The change is required in test_redirect_encoding too. |
|
Thanks @sendaoYan for the PR, and @orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
|
GH-160846 is a backport of this pull request to the 3.15 branch. |
|
GH-160847 is a backport of this pull request to the 3.14 branch. |
…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 <[email protected]> Co-authored-by: Senthil Kumaran <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…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 <[email protected]> Co-authored-by: Senthil Kumaran <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Thanks @orsenthil for verifying and for adding the test_redirect_encoding fix directly to the branch — extracting the unset_proxy_env() helper and using EnvironmentVarGuard.unset() is much cleaner than my original approach. Appreciate the merge and the backports to 3.14 and 3.15! |
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