Skip to content

Commit 496bf56

Browse files
authored
Merge pull request #10416 from sbidoul/test-indented-warnings-sbi
Detect indented ERROR and WARNING messages in tests and ignore own deprecation warnings
2 parents dc8f3a8 + 1800635 commit 496bf56

File tree

6 files changed

+60
-17
lines changed

6 files changed

+60
-17
lines changed

tests/functional/test_download.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,17 @@ def test_download_file_url_existing_bad_download(
11161116
simple_pkg_bytes = simple_pkg.read_bytes()
11171117
url = f"{simple_pkg.as_uri()}#sha256={sha256(simple_pkg_bytes).hexdigest()}"
11181118

1119-
shared_script.pip("download", "-d", str(download_dir), url)
1119+
result = shared_script.pip(
1120+
"download",
1121+
"-d",
1122+
str(download_dir),
1123+
url,
1124+
allow_stderr_warning=True, # bad hash
1125+
)
11201126

11211127
assert simple_pkg_bytes == downloaded_path.read_bytes()
1128+
assert "WARNING: Previously-downloaded file" in result.stderr
1129+
assert "has bad hash. Re-downloading." in result.stderr
11221130

11231131

11241132
def test_download_http_url_bad_hash(
@@ -1144,9 +1152,17 @@ def test_download_http_url_bad_hash(
11441152
base_address = f"http://{mock_server.host}:{mock_server.port}"
11451153
url = f"{base_address}/simple-1.0.tar.gz#sha256={digest}"
11461154

1147-
shared_script.pip("download", "-d", str(download_dir), url)
1155+
result = shared_script.pip(
1156+
"download",
1157+
"-d",
1158+
str(download_dir),
1159+
url,
1160+
allow_stderr_warning=True, # bad hash
1161+
)
11481162

11491163
assert simple_pkg_bytes == downloaded_path.read_bytes()
1164+
assert "WARNING: Previously-downloaded file" in result.stderr
1165+
assert "has bad hash. Re-downloading." in result.stderr
11501166

11511167
mock_server.stop()
11521168
requests = mock_server.get_requests()

tests/functional/test_install.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,16 @@ def test_pep518_with_user_pip(
183183
non-isolated environment, and break pip in the system site-packages,
184184
so that isolated uses of pip will fail.
185185
"""
186-
script.pip("install", "--ignore-installed", "-f", common_wheels, "--user", pip_src)
186+
script.pip(
187+
"install",
188+
"--ignore-installed",
189+
"-f",
190+
common_wheels,
191+
"--user",
192+
pip_src,
193+
# WARNING: The scripts pip, pip3, ... are installed in ... which is not on PATH
194+
allow_stderr_warning=True,
195+
)
187196
system_pip_dir = script.site_packages_path / "pip"
188197
assert not system_pip_dir.exists()
189198
system_pip_dir.mkdir()
@@ -1542,13 +1551,16 @@ def test_install_topological_sort(script: PipTestEnvironment, data: TestData) ->
15421551

15431552
@pytest.mark.usefixtures("with_wheel")
15441553
def test_install_wheel_broken(script: PipTestEnvironment) -> None:
1545-
res = script.pip_install_local("wheelbroken", expect_stderr=True)
1554+
res = script.pip_install_local("wheelbroken", allow_stderr_error=True)
1555+
assert "ERROR: Failed building wheel for wheelbroken" in res.stderr
1556+
# Fallback to setup.py install (https://github.com/pypa/pip/issues/8368)
15461557
assert "Successfully installed wheelbroken-0.1" in str(res), str(res)
15471558

15481559

15491560
@pytest.mark.usefixtures("with_wheel")
15501561
def test_cleanup_after_failed_wheel(script: PipTestEnvironment) -> None:
1551-
res = script.pip_install_local("wheelbrokenafter", expect_stderr=True)
1562+
res = script.pip_install_local("wheelbrokenafter", allow_stderr_error=True)
1563+
assert "ERROR: Failed building wheel for wheelbrokenafter" in res.stderr
15521564
# One of the effects of not cleaning up is broken scripts:
15531565
script_py = script.bin_path / "script.py"
15541566
assert script_py.exists(), script_py
@@ -1577,7 +1589,12 @@ def test_install_builds_wheels(script: PipTestEnvironment, data: TestData) -> No
15771589
# vcs coverage.
15781590
to_install = data.packages.joinpath("requires_wheelbroken_upper")
15791591
res = script.pip(
1580-
"install", "--no-index", "-f", data.find_links, to_install, expect_stderr=True
1592+
"install",
1593+
"--no-index",
1594+
"-f",
1595+
data.find_links,
1596+
to_install,
1597+
allow_stderr_error=True, # error building wheelbroken
15811598
)
15821599
expected = (
15831600
"Successfully installed requires-wheelbroken-upper-0"
@@ -1620,7 +1637,7 @@ def test_install_no_binary_disables_building_wheels(
16201637
"-f",
16211638
data.find_links,
16221639
to_install,
1623-
expect_stderr=True,
1640+
allow_stderr_error=True, # error building wheelbroken
16241641
)
16251642
expected = (
16261643
"Successfully installed requires-wheelbroken-upper-0"

tests/functional/test_install_vcs_git.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _install_version_pkg_only(
9494
script: PipTestEnvironment,
9595
path: Path,
9696
rev: Optional[str] = None,
97-
expect_stderr: bool = False,
97+
allow_stderr_warning: bool = False,
9898
) -> None:
9999
"""
100100
Install the version_pkg package in editable mode (without returning
@@ -106,14 +106,16 @@ def _install_version_pkg_only(
106106
rev: an optional revision to install like a branch name or tag.
107107
"""
108108
version_pkg_url = _make_version_pkg_url(path, rev=rev)
109-
script.pip("install", "-e", version_pkg_url, expect_stderr=expect_stderr)
109+
script.pip(
110+
"install", "-e", version_pkg_url, allow_stderr_warning=allow_stderr_warning
111+
)
110112

111113

112114
def _install_version_pkg(
113115
script: PipTestEnvironment,
114116
path: Path,
115117
rev: Optional[str] = None,
116-
expect_stderr: bool = False,
118+
allow_stderr_warning: bool = False,
117119
) -> str:
118120
"""
119121
Install the version_pkg package in editable mode, and return the version
@@ -128,7 +130,7 @@ def _install_version_pkg(
128130
script,
129131
path,
130132
rev=rev,
131-
expect_stderr=expect_stderr,
133+
allow_stderr_warning=allow_stderr_warning,
132134
)
133135
result = script.run("version_pkg")
134136
version = result.stdout.strip()
@@ -227,7 +229,13 @@ def test_git_with_short_sha1_revisions(script: PipTestEnvironment) -> None:
227229
"HEAD~1",
228230
cwd=version_pkg_path,
229231
).stdout.strip()[:7]
230-
version = _install_version_pkg(script, version_pkg_path, rev=sha1)
232+
version = _install_version_pkg(
233+
script,
234+
version_pkg_path,
235+
rev=sha1,
236+
# WARNING: Did not find branch or tag ..., assuming revision or ref.
237+
allow_stderr_warning=True,
238+
)
231239
assert "0.1" == version
232240

233241

@@ -273,6 +281,8 @@ def test_git_install_ref(script: PipTestEnvironment) -> None:
273281
script,
274282
version_pkg_path,
275283
rev="refs/foo/bar",
284+
# WARNING: Did not find branch or tag ..., assuming revision or ref.
285+
allow_stderr_warning=True,
276286
)
277287
assert "0.1" == version
278288

@@ -294,6 +304,8 @@ def test_git_install_then_install_ref(script: PipTestEnvironment) -> None:
294304
script,
295305
version_pkg_path,
296306
rev="refs/foo/bar",
307+
# WARNING: Did not find branch or tag ..., assuming revision or ref.
308+
allow_stderr_warning=True,
297309
)
298310
assert "0.1" == version
299311

tests/functional/test_uninstall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ def test_uninstall_editable_and_pip_install_easy_install_remove(
684684
os.remove(pip_test_fspkg_pth)
685685

686686
# Uninstall will fail with given warning
687-
uninstall = script.pip("uninstall", "FSPkg", "-y")
687+
uninstall = script.pip("uninstall", "FSPkg", "-y", allow_stderr_warning=True)
688688
assert "Cannot remove entries from nonexistent file" in uninstall.stderr
689689

690690
assert (

tests/lib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from pip._internal.models.selection_prefs import SelectionPreferences
4040
from pip._internal.models.target_python import TargetPython
4141
from pip._internal.network.session import PipSession
42-
from pip._internal.utils.deprecation import DEPRECATION_MSG_PREFIX
4342
from tests.lib.venv import VirtualEnvironment
4443
from tests.lib.wheel import make_wheel
4544

@@ -447,6 +446,7 @@ def _check_stderr(
447446

448447
lines = stderr.splitlines()
449448
for line in lines:
449+
line = line.lstrip()
450450
# First check for logging errors, which we don't allow during
451451
# tests even if allow_stderr_error=True (since a logging error
452452
# would signal a bug in pip's code).
@@ -473,7 +473,7 @@ def _check_stderr(
473473
if allow_stderr_warning:
474474
continue
475475

476-
if line.startswith("WARNING: ") or line.startswith(DEPRECATION_MSG_PREFIX):
476+
if line.startswith("WARNING: "):
477477
reason = (
478478
"stderr has an unexpected warning "
479479
"(pass allow_stderr_warning=True to permit this)"

tests/lib/test_lib.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ def test_run__allow_stderr_warning(self, script: PipTestEnvironment) -> None:
150150
@pytest.mark.parametrize(
151151
"prefix",
152152
(
153-
"DEPRECATION",
154153
"WARNING",
155154
"ERROR",
156155
),
@@ -167,7 +166,6 @@ def test_run__allow_stderr_error(
167166
@pytest.mark.parametrize(
168167
"prefix, expected_start",
169168
(
170-
("DEPRECATION", "stderr has an unexpected warning"),
171169
("WARNING", "stderr has an unexpected warning"),
172170
("ERROR", "stderr has an unexpected error"),
173171
),

0 commit comments

Comments
 (0)