Skip to content

Commit ebdd028

Browse files
usermatthewhughes934
user
authored andcommitted
Split up Windows tests relying on urlunparse behaviour
There was a behavioural change to `urllib.parse.urlunparse`[1] that affects some of our tests on Windows. With the understanding that the new behaviour is indeed desired, split up some tests relying on this behaviour depending on the version of Python. This currently affects only 3.12 and 3.13 but there are other backports for that change in review upstream, so we'll likely need to update this in the future. [1] python/cpython#113563
1 parent 67e2a56 commit ebdd028

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

news/5407ea34-f9bf-4f17-a201-6546bdb9d5d2.trivial.rst

Whitespace-only changes.

tests/lib/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,3 +1375,24 @@ def __call__(
13751375

13761376

13771377
CertFactory = Callable[[], str]
1378+
1379+
# versions containing fix/backport from https://github.com/python/cpython/pull/113563
1380+
# which changed the behavior of `urllib.parse.urlun{parse,split}`
1381+
has_new_urlun_behavior = (
1382+
# https://github.com/python/cpython/commit/387ff96e95b9f8a8cc7e646523ba3175b1350669
1383+
(sys.version_info[:2] == (3, 12) and sys.version_info >= (3, 12, 4))
1384+
or
1385+
# https://github.com/python/cpython/commit/872000606271c52d989e53fe4cc9904343d81855
1386+
(sys.version_info[:2] == (3, 13) and sys.version_info >= (3, 13, 0, "beta", 2))
1387+
)
1388+
1389+
# the above change seems to only impact tests on Windows, so just add skips for that
1390+
skip_needs_new_urlun_behavior_win = pytest.mark.skipif(
1391+
sys.platform != "win32" or not has_new_urlun_behavior,
1392+
reason="testing windows behavior for newer CPython",
1393+
)
1394+
1395+
skip_needs_old_urlun_behavior_win = pytest.mark.skipif(
1396+
sys.platform != "win32" or has_new_urlun_behavior,
1397+
reason="testing windows behavior for older CPython",
1398+
)

tests/unit/test_collector.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
_ensure_quoted_url,
3636
)
3737
from pip._internal.network.session import PipSession
38-
from tests.lib import TestData, make_test_link_collector
38+
from tests.lib import (
39+
TestData,
40+
make_test_link_collector,
41+
skip_needs_new_urlun_behavior_win,
42+
skip_needs_old_urlun_behavior_win,
43+
)
3944

4045
ACCEPT = ", ".join(
4146
[
@@ -383,10 +388,12 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
383388
pytest.param(
384389
"file:///T:/path/with spaces/",
385390
"file:///T:/path/with%20spaces",
386-
marks=pytest.mark.skipif(
387-
"sys.platform != 'win32' or "
388-
"sys.version_info == (3, 13, 0, 'beta', 2)"
389-
),
391+
marks=skip_needs_old_urlun_behavior_win,
392+
),
393+
pytest.param(
394+
"file:///T:/path/with spaces/",
395+
"file://///T:/path/with%20spaces",
396+
marks=skip_needs_new_urlun_behavior_win,
390397
),
391398
# URL with Windows drive letter, running on non-windows
392399
# platform. The `:` after the drive should be quoted.
@@ -399,10 +406,12 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
399406
pytest.param(
400407
"git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0",
401408
"git+file:///T:/with%20space/repo.git@1.0#egg=my-package-1.0",
402-
marks=pytest.mark.skipif(
403-
"sys.platform != 'win32' or "
404-
"sys.version_info == (3, 13, 0, 'beta', 2)"
405-
),
409+
marks=skip_needs_old_urlun_behavior_win,
410+
),
411+
pytest.param(
412+
"git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0",
413+
"git+file://///T:/with%20space/repo.git@1.0#egg=my-package-1.0",
414+
marks=skip_needs_new_urlun_behavior_win,
406415
),
407416
# Test a VCS URL with a Windows drive letter and revision,
408417
# running on non-windows platform.

tests/unit/test_urls.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import pytest
66

77
from pip._internal.utils.urls import path_to_url, url_to_path
8+
from tests.lib import (
9+
skip_needs_new_urlun_behavior_win,
10+
skip_needs_old_urlun_behavior_win,
11+
)
812

913

1014
@pytest.mark.skipif("sys.platform == 'win32'")
@@ -23,12 +27,14 @@ def test_path_to_url_unix() -> None:
2327
pytest.param(
2428
r"\\unc\as\path",
2529
"file://unc/as/path",
26-
marks=pytest.mark.skipif(
27-
"sys.platform != 'win32' or "
28-
"sys.version_info == (3, 13, 0, 'beta', 2)"
29-
),
30+
marks=skip_needs_old_urlun_behavior_win,
3031
id="unc-path",
3132
),
33+
pytest.param(
34+
r"\\unc\as\path",
35+
"file:////unc/as/path",
36+
marks=skip_needs_new_urlun_behavior_win,
37+
),
3238
],
3339
)
3440
def test_path_to_url_win(path: str, url: str) -> None:

0 commit comments

Comments
 (0)