Skip to content

Commit e98cc5c

Browse files
authored
Merge pull request #12894 from notatallshaw/add-pytest-ruff-checks
2 parents 3259c06 + 05d79d8 commit e98cc5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+210
-195
lines changed

news/12894.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add Ruff's Pytest rules to the tests directory.

tests/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def tmp_path(request: pytest.FixtureRequest, tmp_path: Path) -> Iterator[Path]:
216216
shutil.rmtree(tmp_path, ignore_errors=True)
217217

218218

219-
@pytest.fixture()
219+
@pytest.fixture
220220
def tmpdir(tmp_path: Path) -> Path:
221221
"""Override Pytest's ``tmpdir`` with our pathlib implementation.
222222
@@ -477,7 +477,7 @@ def virtualenv_template(
477477
setuptools_install: Path,
478478
wheel_install: Path,
479479
coverage_install: Path,
480-
) -> Iterator[VirtualEnvironment]:
480+
) -> VirtualEnvironment:
481481
venv_type: VirtualEnvironmentType
482482
if request.config.getoption("--use-venv"):
483483
venv_type = "venv"
@@ -522,7 +522,7 @@ def virtualenv_template(
522522
# it's not reused by mistake from one of the copies.
523523
venv_template = tmpdir / "venv_template"
524524
venv.move(venv_template)
525-
yield venv
525+
return venv
526526

527527

528528
@pytest.fixture(scope="session")
@@ -538,14 +538,14 @@ def factory(tmpdir: Path) -> VirtualEnvironment:
538538
@pytest.fixture
539539
def virtualenv(
540540
virtualenv_factory: Callable[[Path], VirtualEnvironment], tmpdir: Path
541-
) -> Iterator[VirtualEnvironment]:
541+
) -> VirtualEnvironment:
542542
"""
543543
Return a virtual environment which is unique to each test function
544544
invocation created inside of a sub directory of the test function's
545545
temporary directory. The returned object is a
546546
``tests.lib.venv.VirtualEnvironment`` object.
547547
"""
548-
yield virtualenv_factory(tmpdir.joinpath("workspace", "venv"))
548+
return virtualenv_factory(tmpdir.joinpath("workspace", "venv"))
549549

550550

551551
@pytest.fixture(scope="session")
@@ -973,7 +973,7 @@ def do_GET(self) -> None:
973973
self._seen_paths.add(self.path)
974974

975975

976-
@pytest.fixture(scope="function")
976+
@pytest.fixture
977977
def html_index_with_onetime_server(
978978
html_index_for_packages: Path,
979979
) -> Iterator[http.server.ThreadingHTTPServer]:

tests/functional/test_download.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ def test_download_use_pep517_propagation(
12341234
assert len(downloads) == 2
12351235

12361236

1237-
@pytest.fixture(scope="function")
1237+
@pytest.fixture
12381238
def download_local_html_index(
12391239
script: PipTestEnvironment,
12401240
html_index_for_packages: Path,
@@ -1265,7 +1265,7 @@ def run_for_generated_index(
12651265
return run_for_generated_index
12661266

12671267

1268-
@pytest.fixture(scope="function")
1268+
@pytest.fixture
12691269
def download_server_html_index(
12701270
script: PipTestEnvironment,
12711271
tmpdir: Path,
@@ -1450,11 +1450,11 @@ def test_produces_error_for_mismatched_package_name_in_metadata(
14501450

14511451
@pytest.mark.parametrize(
14521452
"requirement",
1453-
(
1453+
[
14541454
"requires-simple-extra==0.1",
14551455
"REQUIRES_SIMPLE-EXTRA==0.1",
14561456
"REQUIRES....simple-_-EXTRA==0.1",
1457-
),
1457+
],
14581458
)
14591459
def test_canonicalizes_package_name_before_verifying_metadata(
14601460
download_local_html_index: Callable[..., Tuple[TestPipResult, Path]],

tests/functional/test_fast_deps.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from os.path import basename
77
from typing import Iterable
88

9+
import pytest
910
from pip._vendor.packaging.utils import canonicalize_name
10-
from pytest import mark
1111

1212
from pip._internal.utils.misc import hash_file
1313
from tests.lib import PipTestEnvironment, TestData, TestPipResult
@@ -30,13 +30,13 @@ def assert_installed(script: PipTestEnvironment, names: str) -> None:
3030
assert installed.issuperset(map(canonicalize_name, names))
3131

3232

33-
@mark.network
34-
@mark.parametrize(
35-
("requirement", "expected"),
36-
(
33+
@pytest.mark.network
34+
@pytest.mark.parametrize(
35+
"requirement, expected",
36+
[
3737
("Paste==3.4.2", ("Paste", "six")),
3838
("Paste[flup]==3.4.2", ("Paste", "six", "flup")),
39-
),
39+
],
4040
)
4141
def test_install_from_pypi(
4242
requirement: str, expected: str, script: PipTestEnvironment
@@ -45,13 +45,13 @@ def test_install_from_pypi(
4545
assert_installed(script, expected)
4646

4747

48-
@mark.network
49-
@mark.parametrize(
50-
("requirement", "expected"),
51-
(
48+
@pytest.mark.network
49+
@pytest.mark.parametrize(
50+
"requirement, expected",
51+
[
5252
("Paste==3.4.2", ("Paste-3.4.2-*.whl", "six-*.whl")),
5353
("Paste[flup]==3.4.2", ("Paste-3.4.2-*.whl", "six-*.whl", "flup-*")),
54-
),
54+
],
5555
)
5656
def test_download_from_pypi(
5757
requirement: str, expected: Iterable[str], script: PipTestEnvironment
@@ -61,7 +61,7 @@ def test_download_from_pypi(
6161
assert all(fnmatch.filter(created, f) for f in expected)
6262

6363

64-
@mark.network
64+
@pytest.mark.network
6565
def test_build_wheel_with_deps(data: TestData, script: PipTestEnvironment) -> None:
6666
result = pip(script, "wheel", os.fspath(data.packages / "requiresPaste"))
6767
created = [basename(f) for f in result.files_created]
@@ -70,7 +70,7 @@ def test_build_wheel_with_deps(data: TestData, script: PipTestEnvironment) -> No
7070
assert fnmatch.filter(created, "six-*.whl")
7171

7272

73-
@mark.network
73+
@pytest.mark.network
7474
def test_require_hash(script: PipTestEnvironment, tmp_path: pathlib.Path) -> None:
7575
reqs = tmp_path / "requirements.txt"
7676
reqs.write_text(
@@ -91,7 +91,7 @@ def test_require_hash(script: PipTestEnvironment, tmp_path: pathlib.Path) -> Non
9191
assert fnmatch.filter(created, "idna-2.10*")
9292

9393

94-
@mark.network
94+
@pytest.mark.network
9595
def test_hash_mismatch(script: PipTestEnvironment, tmp_path: pathlib.Path) -> None:
9696
reqs = tmp_path / "requirements.txt"
9797
reqs.write_text("idna==2.10 --hash=sha256:irna")
@@ -105,7 +105,7 @@ def test_hash_mismatch(script: PipTestEnvironment, tmp_path: pathlib.Path) -> No
105105
assert "DO NOT MATCH THE HASHES" in result.stderr
106106

107107

108-
@mark.network
108+
@pytest.mark.network
109109
def test_hash_mismatch_existing_download_for_metadata_only_wheel(
110110
script: PipTestEnvironment, tmp_path: pathlib.Path
111111
) -> None:

tests/functional/test_install.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
)
4343

4444

45-
@pytest.mark.parametrize("command", ("install", "wheel"))
46-
@pytest.mark.parametrize("variant", ("missing_setuptools", "bad_setuptools"))
45+
@pytest.mark.parametrize("command", ["install", "wheel"])
46+
@pytest.mark.parametrize("variant", ["missing_setuptools", "bad_setuptools"])
4747
def test_pep518_uses_build_env(
4848
script: PipTestEnvironment,
4949
data: TestData,
@@ -105,16 +105,13 @@ def test_pep518_refuses_conflicting_requires(
105105
result = script.pip_install_local(
106106
"-f", script.scratch_path, project_dir, expect_error=True
107107
)
108+
assert result.returncode != 0
108109
assert (
109-
result.returncode != 0
110-
and (
111-
f"Some build dependencies for {project_dir.as_uri()} conflict "
112-
"with PEP 517/518 supported "
113-
"requirements: setuptools==1.0 is incompatible with "
114-
"setuptools>=40.8.0."
115-
)
116-
in result.stderr
117-
), str(result)
110+
f"Some build dependencies for {project_dir.as_uri()} conflict "
111+
"with PEP 517/518 supported "
112+
"requirements: setuptools==1.0 is incompatible with "
113+
"setuptools>=40.8.0."
114+
) in result.stderr, str(result)
118115

119116

120117
def test_pep518_refuses_invalid_requires(
@@ -243,10 +240,10 @@ def test_pep518_with_namespace_package(
243240
)
244241

245242

246-
@pytest.mark.parametrize("command", ("install", "wheel"))
243+
@pytest.mark.parametrize("command", ["install", "wheel"])
247244
@pytest.mark.parametrize(
248245
"package",
249-
("pep518_forkbomb", "pep518_twin_forkbombs_first", "pep518_twin_forkbombs_second"),
246+
["pep518_forkbomb", "pep518_twin_forkbombs_first", "pep518_twin_forkbombs_second"],
250247
)
251248
def test_pep518_forkbombs(
252249
script: PipTestEnvironment,
@@ -1253,7 +1250,7 @@ def test_install_nonlocal_compatible_wheel_path(
12531250
assert result.returncode == ERROR
12541251

12551252

1256-
@pytest.mark.parametrize("opt", ("--target", "--prefix"))
1253+
@pytest.mark.parametrize("opt", ["--target", "--prefix"])
12571254
def test_install_with_target_or_prefix_and_scripts_no_warning(
12581255
opt: str, script: PipTestEnvironment
12591256
) -> None:
@@ -2027,7 +2024,7 @@ def test_install_pep508_with_url_in_install_requires(
20272024

20282025

20292026
@pytest.mark.network
2030-
@pytest.mark.parametrize("index", (PyPI.simple_url, TestPyPI.simple_url))
2027+
@pytest.mark.parametrize("index", [PyPI.simple_url, TestPyPI.simple_url])
20312028
def test_install_from_test_pypi_with_ext_url_dep_is_blocked(
20322029
script: PipTestEnvironment, index: str
20332030
) -> None:
@@ -2309,10 +2306,10 @@ def test_error_all_yanked_files_and_no_pin(
23092306
expect_error=True,
23102307
)
23112308
# Make sure an error is raised
2312-
assert (
2313-
result.returncode == 1
2314-
and "ERROR: No matching distribution found for simple\n" in result.stderr
2315-
), str(result)
2309+
assert result.returncode == 1
2310+
assert "ERROR: No matching distribution found for simple\n" in result.stderr, str(
2311+
result
2312+
)
23162313

23172314

23182315
@pytest.mark.parametrize(
@@ -2392,7 +2389,7 @@ def test_install_skip_work_dir_pkg(script: PipTestEnvironment, data: TestData) -
23922389

23932390

23942391
@pytest.mark.parametrize(
2395-
"package_name", ("simple-package", "simple_package", "simple.package")
2392+
"package_name", ["simple-package", "simple_package", "simple.package"]
23962393
)
23972394
def test_install_verify_package_name_normalization(
23982395
script: PipTestEnvironment, package_name: str
@@ -2449,7 +2446,7 @@ def install_find_links(
24492446

24502447
@pytest.mark.parametrize(
24512448
"with_target_dir",
2452-
(True, False),
2449+
[True, False],
24532450
)
24542451
def test_install_dry_run_nothing_installed(
24552452
script: PipTestEnvironment,
@@ -2618,7 +2615,7 @@ def test_install_pip_prints_req_chain_pypi(script: PipTestEnvironment) -> None:
26182615
)
26192616

26202617

2621-
@pytest.mark.parametrize("common_prefix", ("", "linktest-1.0/"))
2618+
@pytest.mark.parametrize("common_prefix", ["", "linktest-1.0/"])
26222619
def test_install_sdist_links(script: PipTestEnvironment, common_prefix: str) -> None:
26232620
"""
26242621
Test installing an sdist with hard and symbolic links.

tests/functional/test_install_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def keyring_provider_implementation(request: pytest.FixtureRequest) -> str:
361361
return request.param
362362

363363

364-
@pytest.fixture()
364+
@pytest.fixture
365365
def flags(
366366
request: pytest.FixtureRequest,
367367
interactive: bool,

tests/functional/test_install_reqs.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ArgRecordingSdistMaker(Protocol):
3232
def __call__(self, name: str, **kwargs: Any) -> ArgRecordingSdist: ...
3333

3434

35-
@pytest.fixture()
35+
@pytest.fixture
3636
def arg_recording_sdist_maker(
3737
script: PipTestEnvironment,
3838
) -> ArgRecordingSdistMaker:
@@ -624,10 +624,9 @@ def test_install_distribution_duplicate_extras(
624624
) -> None:
625625
to_install = data.packages.joinpath("LocalExtras")
626626
package_name = f"{to_install}[bar]"
627-
with pytest.raises(AssertionError):
628-
result = script.pip_install_local(package_name, package_name)
629-
expected = f"Double requirement given: {package_name}"
630-
assert expected in result.stderr
627+
result = script.pip_install_local(package_name, package_name)
628+
unexpected = f"Double requirement given: {package_name}"
629+
assert unexpected not in result.stderr
631630

632631

633632
def test_install_distribution_union_with_constraints(

tests/functional/test_invalid_versions_and_specifiers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ def test_show_require_invalid_version(
136136
elif select_backend().NAME == "pkg_resources":
137137
assert "Required-by: \n" in result.stdout
138138
else:
139-
assert False, "Unknown metadata backend"
139+
pytest.fail("Unknown metadata backend")

tests/functional/test_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,4 +749,4 @@ def test_list_pep610_editable(script: PipTestEnvironment) -> None:
749749
assert item["editable_project_location"]
750750
break
751751
else:
752-
assert False, "package 'testpkg' not found in pip list result"
752+
pytest.fail("package 'testpkg' not found in pip list result")

tests/functional/test_new_resolver.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def assert_editable(script: PipTestEnvironment, *args: str) -> None:
3535
), f"{args!r} not all found in {script.site_packages_path!r}"
3636

3737

38-
@pytest.fixture()
38+
@pytest.fixture
3939
def make_fake_wheel(script: PipTestEnvironment) -> MakeFakeWheel:
4040
def _make_fake_wheel(name: str, version: str, wheel_tag: str) -> pathlib.Path:
4141
wheel_house = script.scratch_path.joinpath("wheelhouse")
@@ -2299,8 +2299,8 @@ def test_new_resolver_dont_backtrack_on_extra_if_base_constrained(
22992299
script.assert_installed(pkg="1.0", dep="1.0")
23002300

23012301

2302-
@pytest.mark.parametrize("swap_order", (True, False))
2303-
@pytest.mark.parametrize("two_extras", (True, False))
2302+
@pytest.mark.parametrize("swap_order", [True, False])
2303+
@pytest.mark.parametrize("two_extras", [True, False])
23042304
def test_new_resolver_dont_backtrack_on_extra_if_base_constrained_in_requirement(
23052305
script: PipTestEnvironment, swap_order: bool, two_extras: bool
23062306
) -> None:
@@ -2337,8 +2337,8 @@ def test_new_resolver_dont_backtrack_on_extra_if_base_constrained_in_requirement
23372337
script.assert_installed(pkg="1.0", dep="1.0")
23382338

23392339

2340-
@pytest.mark.parametrize("swap_order", (True, False))
2341-
@pytest.mark.parametrize("two_extras", (True, False))
2340+
@pytest.mark.parametrize("swap_order", [True, False])
2341+
@pytest.mark.parametrize("two_extras", [True, False])
23422342
def test_new_resolver_dont_backtrack_on_conflicting_constraints_on_extras(
23432343
tmpdir: pathlib.Path,
23442344
virtualenv: VirtualEnvironment,
@@ -2518,7 +2518,7 @@ def test_new_resolver_works_when_failing_package_builds_are_disallowed(
25182518
script.assert_installed(pkg2="1.0", pkg1="1.0")
25192519

25202520

2521-
@pytest.mark.parametrize("swap_order", (True, False))
2521+
@pytest.mark.parametrize("swap_order", [True, False])
25222522
def test_new_resolver_comes_from_with_extra(
25232523
script: PipTestEnvironment, swap_order: bool
25242524
) -> None:

0 commit comments

Comments
 (0)