diff --git a/news/12894.trivial.rst b/news/12894.trivial.rst new file mode 100644 index 00000000000..51e4c8b0338 --- /dev/null +++ b/news/12894.trivial.rst @@ -0,0 +1 @@ +Add Ruff's Pytest rules to the tests directory. diff --git a/tests/conftest.py b/tests/conftest.py index 9850da55d56..da4ab5b9dfb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -216,7 +216,7 @@ def tmp_path(request: pytest.FixtureRequest, tmp_path: Path) -> Iterator[Path]: shutil.rmtree(tmp_path, ignore_errors=True) -@pytest.fixture() +@pytest.fixture def tmpdir(tmp_path: Path) -> Path: """Override Pytest's ``tmpdir`` with our pathlib implementation. @@ -477,7 +477,7 @@ def virtualenv_template( setuptools_install: Path, wheel_install: Path, coverage_install: Path, -) -> Iterator[VirtualEnvironment]: +) -> VirtualEnvironment: venv_type: VirtualEnvironmentType if request.config.getoption("--use-venv"): venv_type = "venv" @@ -522,7 +522,7 @@ def virtualenv_template( # it's not reused by mistake from one of the copies. venv_template = tmpdir / "venv_template" venv.move(venv_template) - yield venv + return venv @pytest.fixture(scope="session") @@ -538,14 +538,14 @@ def factory(tmpdir: Path) -> VirtualEnvironment: @pytest.fixture def virtualenv( virtualenv_factory: Callable[[Path], VirtualEnvironment], tmpdir: Path -) -> Iterator[VirtualEnvironment]: +) -> VirtualEnvironment: """ Return a virtual environment which is unique to each test function invocation created inside of a sub directory of the test function's temporary directory. The returned object is a ``tests.lib.venv.VirtualEnvironment`` object. """ - yield virtualenv_factory(tmpdir.joinpath("workspace", "venv")) + return virtualenv_factory(tmpdir.joinpath("workspace", "venv")) @pytest.fixture(scope="session") @@ -973,7 +973,7 @@ def do_GET(self) -> None: self._seen_paths.add(self.path) -@pytest.fixture(scope="function") +@pytest.fixture def html_index_with_onetime_server( html_index_for_packages: Path, ) -> Iterator[http.server.ThreadingHTTPServer]: diff --git a/tests/functional/test_download.py b/tests/functional/test_download.py index 450690c1675..d469e71c360 100644 --- a/tests/functional/test_download.py +++ b/tests/functional/test_download.py @@ -1234,7 +1234,7 @@ def test_download_use_pep517_propagation( assert len(downloads) == 2 -@pytest.fixture(scope="function") +@pytest.fixture def download_local_html_index( script: PipTestEnvironment, html_index_for_packages: Path, @@ -1265,7 +1265,7 @@ def run_for_generated_index( return run_for_generated_index -@pytest.fixture(scope="function") +@pytest.fixture def download_server_html_index( script: PipTestEnvironment, tmpdir: Path, @@ -1450,11 +1450,11 @@ def test_produces_error_for_mismatched_package_name_in_metadata( @pytest.mark.parametrize( "requirement", - ( + [ "requires-simple-extra==0.1", "REQUIRES_SIMPLE-EXTRA==0.1", "REQUIRES....simple-_-EXTRA==0.1", - ), + ], ) def test_canonicalizes_package_name_before_verifying_metadata( download_local_html_index: Callable[..., Tuple[TestPipResult, Path]], diff --git a/tests/functional/test_fast_deps.py b/tests/functional/test_fast_deps.py index 9e529c0891e..5a910b89763 100644 --- a/tests/functional/test_fast_deps.py +++ b/tests/functional/test_fast_deps.py @@ -6,8 +6,8 @@ from os.path import basename from typing import Iterable +import pytest from pip._vendor.packaging.utils import canonicalize_name -from pytest import mark from pip._internal.utils.misc import hash_file from tests.lib import PipTestEnvironment, TestData, TestPipResult @@ -30,13 +30,13 @@ def assert_installed(script: PipTestEnvironment, names: str) -> None: assert installed.issuperset(map(canonicalize_name, names)) -@mark.network -@mark.parametrize( - ("requirement", "expected"), - ( +@pytest.mark.network +@pytest.mark.parametrize( + "requirement, expected", + [ ("Paste==3.4.2", ("Paste", "six")), ("Paste[flup]==3.4.2", ("Paste", "six", "flup")), - ), + ], ) def test_install_from_pypi( requirement: str, expected: str, script: PipTestEnvironment @@ -45,13 +45,13 @@ def test_install_from_pypi( assert_installed(script, expected) -@mark.network -@mark.parametrize( - ("requirement", "expected"), - ( +@pytest.mark.network +@pytest.mark.parametrize( + "requirement, expected", + [ ("Paste==3.4.2", ("Paste-3.4.2-*.whl", "six-*.whl")), ("Paste[flup]==3.4.2", ("Paste-3.4.2-*.whl", "six-*.whl", "flup-*")), - ), + ], ) def test_download_from_pypi( requirement: str, expected: Iterable[str], script: PipTestEnvironment @@ -61,7 +61,7 @@ def test_download_from_pypi( assert all(fnmatch.filter(created, f) for f in expected) -@mark.network +@pytest.mark.network def test_build_wheel_with_deps(data: TestData, script: PipTestEnvironment) -> None: result = pip(script, "wheel", os.fspath(data.packages / "requiresPaste")) created = [basename(f) for f in result.files_created] @@ -70,7 +70,7 @@ def test_build_wheel_with_deps(data: TestData, script: PipTestEnvironment) -> No assert fnmatch.filter(created, "six-*.whl") -@mark.network +@pytest.mark.network def test_require_hash(script: PipTestEnvironment, tmp_path: pathlib.Path) -> None: reqs = tmp_path / "requirements.txt" reqs.write_text( @@ -91,7 +91,7 @@ def test_require_hash(script: PipTestEnvironment, tmp_path: pathlib.Path) -> Non assert fnmatch.filter(created, "idna-2.10*") -@mark.network +@pytest.mark.network def test_hash_mismatch(script: PipTestEnvironment, tmp_path: pathlib.Path) -> None: reqs = tmp_path / "requirements.txt" reqs.write_text("idna==2.10 --hash=sha256:irna") @@ -105,7 +105,7 @@ def test_hash_mismatch(script: PipTestEnvironment, tmp_path: pathlib.Path) -> No assert "DO NOT MATCH THE HASHES" in result.stderr -@mark.network +@pytest.mark.network def test_hash_mismatch_existing_download_for_metadata_only_wheel( script: PipTestEnvironment, tmp_path: pathlib.Path ) -> None: diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index c6b5635f8fe..8c30a69b515 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -42,8 +42,8 @@ ) -@pytest.mark.parametrize("command", ("install", "wheel")) -@pytest.mark.parametrize("variant", ("missing_setuptools", "bad_setuptools")) +@pytest.mark.parametrize("command", ["install", "wheel"]) +@pytest.mark.parametrize("variant", ["missing_setuptools", "bad_setuptools"]) def test_pep518_uses_build_env( script: PipTestEnvironment, data: TestData, @@ -105,16 +105,13 @@ def test_pep518_refuses_conflicting_requires( result = script.pip_install_local( "-f", script.scratch_path, project_dir, expect_error=True ) + assert result.returncode != 0 assert ( - result.returncode != 0 - and ( - f"Some build dependencies for {project_dir.as_uri()} conflict " - "with PEP 517/518 supported " - "requirements: setuptools==1.0 is incompatible with " - "setuptools>=40.8.0." - ) - in result.stderr - ), str(result) + f"Some build dependencies for {project_dir.as_uri()} conflict " + "with PEP 517/518 supported " + "requirements: setuptools==1.0 is incompatible with " + "setuptools>=40.8.0." + ) in result.stderr, str(result) def test_pep518_refuses_invalid_requires( @@ -243,10 +240,10 @@ def test_pep518_with_namespace_package( ) -@pytest.mark.parametrize("command", ("install", "wheel")) +@pytest.mark.parametrize("command", ["install", "wheel"]) @pytest.mark.parametrize( "package", - ("pep518_forkbomb", "pep518_twin_forkbombs_first", "pep518_twin_forkbombs_second"), + ["pep518_forkbomb", "pep518_twin_forkbombs_first", "pep518_twin_forkbombs_second"], ) def test_pep518_forkbombs( script: PipTestEnvironment, @@ -1253,7 +1250,7 @@ def test_install_nonlocal_compatible_wheel_path( assert result.returncode == ERROR -@pytest.mark.parametrize("opt", ("--target", "--prefix")) +@pytest.mark.parametrize("opt", ["--target", "--prefix"]) def test_install_with_target_or_prefix_and_scripts_no_warning( opt: str, script: PipTestEnvironment ) -> None: @@ -2027,7 +2024,7 @@ def test_install_pep508_with_url_in_install_requires( @pytest.mark.network -@pytest.mark.parametrize("index", (PyPI.simple_url, TestPyPI.simple_url)) +@pytest.mark.parametrize("index", [PyPI.simple_url, TestPyPI.simple_url]) def test_install_from_test_pypi_with_ext_url_dep_is_blocked( script: PipTestEnvironment, index: str ) -> None: @@ -2309,10 +2306,10 @@ def test_error_all_yanked_files_and_no_pin( expect_error=True, ) # Make sure an error is raised - assert ( - result.returncode == 1 - and "ERROR: No matching distribution found for simple\n" in result.stderr - ), str(result) + assert result.returncode == 1 + assert "ERROR: No matching distribution found for simple\n" in result.stderr, str( + result + ) @pytest.mark.parametrize( @@ -2392,7 +2389,7 @@ def test_install_skip_work_dir_pkg(script: PipTestEnvironment, data: TestData) - @pytest.mark.parametrize( - "package_name", ("simple-package", "simple_package", "simple.package") + "package_name", ["simple-package", "simple_package", "simple.package"] ) def test_install_verify_package_name_normalization( script: PipTestEnvironment, package_name: str @@ -2449,7 +2446,7 @@ def install_find_links( @pytest.mark.parametrize( "with_target_dir", - (True, False), + [True, False], ) def test_install_dry_run_nothing_installed( script: PipTestEnvironment, @@ -2618,7 +2615,7 @@ def test_install_pip_prints_req_chain_pypi(script: PipTestEnvironment) -> None: ) -@pytest.mark.parametrize("common_prefix", ("", "linktest-1.0/")) +@pytest.mark.parametrize("common_prefix", ["", "linktest-1.0/"]) def test_install_sdist_links(script: PipTestEnvironment, common_prefix: str) -> None: """ Test installing an sdist with hard and symbolic links. diff --git a/tests/functional/test_install_config.py b/tests/functional/test_install_config.py index 9374fade121..d111bc5f7bc 100644 --- a/tests/functional/test_install_config.py +++ b/tests/functional/test_install_config.py @@ -361,7 +361,7 @@ def keyring_provider_implementation(request: pytest.FixtureRequest) -> str: return request.param -@pytest.fixture() +@pytest.fixture def flags( request: pytest.FixtureRequest, interactive: bool, diff --git a/tests/functional/test_install_reqs.py b/tests/functional/test_install_reqs.py index 1db749b145c..b1aed6ad3f4 100644 --- a/tests/functional/test_install_reqs.py +++ b/tests/functional/test_install_reqs.py @@ -32,7 +32,7 @@ class ArgRecordingSdistMaker(Protocol): def __call__(self, name: str, **kwargs: Any) -> ArgRecordingSdist: ... -@pytest.fixture() +@pytest.fixture def arg_recording_sdist_maker( script: PipTestEnvironment, ) -> ArgRecordingSdistMaker: @@ -624,10 +624,9 @@ def test_install_distribution_duplicate_extras( ) -> None: to_install = data.packages.joinpath("LocalExtras") package_name = f"{to_install}[bar]" - with pytest.raises(AssertionError): - result = script.pip_install_local(package_name, package_name) - expected = f"Double requirement given: {package_name}" - assert expected in result.stderr + result = script.pip_install_local(package_name, package_name) + unexpected = f"Double requirement given: {package_name}" + assert unexpected not in result.stderr def test_install_distribution_union_with_constraints( diff --git a/tests/functional/test_invalid_versions_and_specifiers.py b/tests/functional/test_invalid_versions_and_specifiers.py index 21ce02085fc..4867fe54beb 100644 --- a/tests/functional/test_invalid_versions_and_specifiers.py +++ b/tests/functional/test_invalid_versions_and_specifiers.py @@ -136,4 +136,4 @@ def test_show_require_invalid_version( elif select_backend().NAME == "pkg_resources": assert "Required-by: \n" in result.stdout else: - assert False, "Unknown metadata backend" + pytest.fail("Unknown metadata backend") diff --git a/tests/functional/test_list.py b/tests/functional/test_list.py index 5164c1d5c39..43998600eb6 100644 --- a/tests/functional/test_list.py +++ b/tests/functional/test_list.py @@ -749,4 +749,4 @@ def test_list_pep610_editable(script: PipTestEnvironment) -> None: assert item["editable_project_location"] break else: - assert False, "package 'testpkg' not found in pip list result" + pytest.fail("package 'testpkg' not found in pip list result") diff --git a/tests/functional/test_new_resolver.py b/tests/functional/test_new_resolver.py index 5be2eb93ace..7ab8a0bb850 100644 --- a/tests/functional/test_new_resolver.py +++ b/tests/functional/test_new_resolver.py @@ -35,7 +35,7 @@ def assert_editable(script: PipTestEnvironment, *args: str) -> None: ), f"{args!r} not all found in {script.site_packages_path!r}" -@pytest.fixture() +@pytest.fixture def make_fake_wheel(script: PipTestEnvironment) -> MakeFakeWheel: def _make_fake_wheel(name: str, version: str, wheel_tag: str) -> pathlib.Path: wheel_house = script.scratch_path.joinpath("wheelhouse") @@ -2299,8 +2299,8 @@ def test_new_resolver_dont_backtrack_on_extra_if_base_constrained( script.assert_installed(pkg="1.0", dep="1.0") -@pytest.mark.parametrize("swap_order", (True, False)) -@pytest.mark.parametrize("two_extras", (True, False)) +@pytest.mark.parametrize("swap_order", [True, False]) +@pytest.mark.parametrize("two_extras", [True, False]) def test_new_resolver_dont_backtrack_on_extra_if_base_constrained_in_requirement( script: PipTestEnvironment, swap_order: bool, two_extras: bool ) -> None: @@ -2337,8 +2337,8 @@ def test_new_resolver_dont_backtrack_on_extra_if_base_constrained_in_requirement script.assert_installed(pkg="1.0", dep="1.0") -@pytest.mark.parametrize("swap_order", (True, False)) -@pytest.mark.parametrize("two_extras", (True, False)) +@pytest.mark.parametrize("swap_order", [True, False]) +@pytest.mark.parametrize("two_extras", [True, False]) def test_new_resolver_dont_backtrack_on_conflicting_constraints_on_extras( tmpdir: pathlib.Path, virtualenv: VirtualEnvironment, @@ -2518,7 +2518,7 @@ def test_new_resolver_works_when_failing_package_builds_are_disallowed( script.assert_installed(pkg2="1.0", pkg1="1.0") -@pytest.mark.parametrize("swap_order", (True, False)) +@pytest.mark.parametrize("swap_order", [True, False]) def test_new_resolver_comes_from_with_extra( script: PipTestEnvironment, swap_order: bool ) -> None: diff --git a/tests/functional/test_new_resolver_target.py b/tests/functional/test_new_resolver_target.py index a81cfe5e83d..4434c276fca 100644 --- a/tests/functional/test_new_resolver_target.py +++ b/tests/functional/test_new_resolver_target.py @@ -10,7 +10,7 @@ MakeFakeWheel = Callable[[str], str] -@pytest.fixture() +@pytest.fixture def make_fake_wheel(script: PipTestEnvironment) -> MakeFakeWheel: def _make_fake_wheel(wheel_tag: str) -> str: wheel_house = script.scratch_path.joinpath("wheelhouse") diff --git a/tests/functional/test_new_resolver_user.py b/tests/functional/test_new_resolver_user.py index 1660924f28c..5d061f9012c 100644 --- a/tests/functional/test_new_resolver_user.py +++ b/tests/functional/test_new_resolver_user.py @@ -91,7 +91,7 @@ def test_new_resolver_install_user_conflict_in_user_site( result.did_not_create(base_2_dist_info) -@pytest.fixture() +@pytest.fixture def patch_dist_in_site_packages(virtualenv: VirtualEnvironment) -> None: # Since the tests are run from a virtualenv, and to avoid the "Will not # install to the usersite because it will lack sys.path precedence..." diff --git a/tests/functional/test_pep517.py b/tests/functional/test_pep517.py index 78a6c2bbc6c..4e0c16358af 100644 --- a/tests/functional/test_pep517.py +++ b/tests/functional/test_pep517.py @@ -44,7 +44,8 @@ def test_backend(tmpdir: Path, data: TestData) -> None: finder = make_test_finder(find_links=[data.backends]) env.install_requirements(finder, ["dummy_backend"], "normal", kind="Installing") conflicting, missing = env.check_requirements(["dummy_backend"]) - assert not conflicting and not missing + assert not conflicting + assert not missing assert hasattr(req.pep517_backend, "build_wheel") with env: assert req.pep517_backend is not None @@ -163,7 +164,8 @@ def test_conflicting_pep517_backend_requirements( "dependencies: simplewheel==1.0 is incompatible with " "simplewheel==2.0." ) - assert result.returncode != 0 and msg in result.stderr, str(result) + assert result.returncode != 0 + assert msg in result.stderr, str(result) def test_no_check_build_deps( @@ -208,7 +210,8 @@ def test_validate_missing_pep517_backend_requirements( f"Some build dependencies for {project_dir.as_uri()} are missing: " "'simplewheel==1.0', 'test_backend'." ) - assert result.returncode != 0 and msg in result.stderr, str(result) + assert result.returncode != 0 + assert msg in result.stderr, str(result) def test_validate_conflicting_pep517_backend_requirements( @@ -235,7 +238,8 @@ def test_validate_conflicting_pep517_backend_requirements( "dependencies: simplewheel==2.0 is incompatible with " "simplewheel==1.0." ) - assert result.returncode != 0 and msg in result.stderr, str(result) + assert result.returncode != 0 + assert msg in result.stderr, str(result) def test_pep517_backend_requirements_satisfied_by_prerelease( diff --git a/tests/functional/test_pep668.py b/tests/functional/test_pep668.py index 3c1085668fc..a4920dfce5e 100644 --- a/tests/functional/test_pep668.py +++ b/tests/functional/test_pep668.py @@ -9,7 +9,7 @@ from tests.lib.venv import VirtualEnvironment -@pytest.fixture() +@pytest.fixture def patch_check_externally_managed(virtualenv: VirtualEnvironment) -> None: # Since the tests are run from a virtual environment, and we can't # guarantee access to the actual stdlib location (where EXTERNALLY-MANAGED diff --git a/tests/functional/test_truststore.py b/tests/functional/test_truststore.py index c534ddb954d..8985665906e 100644 --- a/tests/functional/test_truststore.py +++ b/tests/functional/test_truststore.py @@ -7,7 +7,7 @@ PipRunner = Callable[..., TestPipResult] -@pytest.fixture() +@pytest.fixture def pip_no_truststore(script: PipTestEnvironment) -> PipRunner: def pip(*args: str, **kwargs: Any) -> TestPipResult: return script.pip(*args, "--use-deprecated=legacy-certs", **kwargs) diff --git a/tests/functional/test_uninstall.py b/tests/functional/test_uninstall.py index 5bf64119e34..58e141e54ad 100644 --- a/tests/functional/test_uninstall.py +++ b/tests/functional/test_uninstall.py @@ -669,7 +669,7 @@ def test_uninstall_editable_and_pip_install( script.assert_not_installed("FSPkg") -@pytest.fixture() +@pytest.fixture def move_easy_install_pth(script: PipTestEnvironment) -> Iterator[None]: """Move easy-install.pth out of the way for testing easy_install.""" easy_install_pth = join(script.site_packages_path, "easy-install.pth") diff --git a/tests/functional/test_vcs_git.py b/tests/functional/test_vcs_git.py index 1ec09c73e47..a7276e2b6a5 100644 --- a/tests/functional/test_vcs_git.py +++ b/tests/functional/test_vcs_git.py @@ -319,11 +319,11 @@ def _initialize_clonetest_server( @pytest.mark.parametrize( "version_out, expected_message", - ( + [ ("git version -2.25.1", "Can't parse git version: git version -2.25.1"), ("git version 2.a.1", "Can't parse git version: git version 2.a.1"), ("git ver. 2.25.1", "Can't parse git version: git ver. 2.25.1"), - ), + ], ) @patch("pip._internal.vcs.versioncontrol.VersionControl.run_command") def test_git_parse_fail_warning( diff --git a/tests/lib/test_lib.py b/tests/lib/test_lib.py index 09a1cc738f9..dba55a82809 100644 --- a/tests/lib/test_lib.py +++ b/tests/lib/test_lib.py @@ -115,11 +115,11 @@ def run_with_log_command( @pytest.mark.parametrize( "prefix", - ( + [ "DEBUG", "INFO", "FOO", - ), + ], ) def test_run__allowed_stderr(self, script: PipTestEnvironment, prefix: str) -> None: """ @@ -150,10 +150,10 @@ def test_run__allow_stderr_warning(self, script: PipTestEnvironment) -> None: @pytest.mark.parametrize( "prefix", - ( + [ "WARNING", "ERROR", - ), + ], ) def test_run__allow_stderr_error( self, script: PipTestEnvironment, prefix: str @@ -166,10 +166,10 @@ def test_run__allow_stderr_error( @pytest.mark.parametrize( "prefix, expected_start", - ( + [ ("WARNING", "stderr has an unexpected warning"), ("ERROR", "stderr has an unexpected error"), - ), + ], ) def test_run__unexpected_stderr( self, script: PipTestEnvironment, prefix: str, expected_start: str @@ -227,10 +227,10 @@ def test_run__allow_stderr_warning_false_error_with_expect_stderr( @pytest.mark.parametrize( "arg_name", - ( + [ "expect_error", "allow_stderr_error", - ), + ], ) def test_run__allow_stderr_warning_false_error( self, script: PipTestEnvironment, arg_name: str diff --git a/tests/ruff.toml b/tests/ruff.toml new file mode 100644 index 00000000000..366d8a5814b --- /dev/null +++ b/tests/ruff.toml @@ -0,0 +1,14 @@ +# Extend the `pyproject.toml` file in the parent directory. +extend = "../pyproject.toml" + +# And extend linting to include pytest specific rules and configuration +[lint] +extend-select = ["PT"] +ignore = ["PT004", "PT011"] + +[lint.flake8-pytest-style] +mark-parentheses = false +fixture-parentheses = false +parametrize-names-type = "csv" +parametrize-values-type = "list" +parametrize-values-row-type = "tuple" diff --git a/tests/unit/metadata/test_metadata.py b/tests/unit/metadata/test_metadata.py index ccc8ceb2e75..caa2dea8c91 100644 --- a/tests/unit/metadata/test_metadata.py +++ b/tests/unit/metadata/test_metadata.py @@ -119,7 +119,8 @@ def test_dist_found_in_directory_named_whl(tmp_path: Path) -> None: info_path.joinpath("METADATA").write_text("Name: pkg") location = os.fspath(dir_path) dist = get_environment([location]).get_distribution("pkg") - assert dist is not None and dist.location is not None + assert dist is not None + assert dist.location is not None assert Path(dist.location) == Path(location) @@ -127,17 +128,18 @@ def test_dist_found_in_zip(tmp_path: Path) -> None: location = os.fspath(tmp_path.joinpath("pkg.zip")) make_wheel(name="pkg", version="1").save_to(location) dist = get_environment([location]).get_distribution("pkg") - assert dist is not None and dist.location is not None + assert dist is not None + assert dist.location is not None assert Path(dist.location) == Path(location) @pytest.mark.parametrize( "path", - ( + [ "/path/to/foo.egg-info".replace("/", os.path.sep), # Tests issue fixed by https://github.com/pypa/pip/pull/2530 "/path/to/foo.egg-info/".replace("/", os.path.sep), - ), + ], ) def test_trailing_slash_directory_metadata(path: str) -> None: dist = get_directory_distribution(path) diff --git a/tests/unit/resolution_resolvelib/conftest.py b/tests/unit/resolution_resolvelib/conftest.py index a4ee32444e2..348396bafe2 100644 --- a/tests/unit/resolution_resolvelib/conftest.py +++ b/tests/unit/resolution_resolvelib/conftest.py @@ -21,13 +21,13 @@ @pytest.fixture -def finder(data: TestData) -> Iterator[PackageFinder]: +def finder(data: TestData) -> PackageFinder: session = PipSession() scope = SearchScope([str(data.packages)], [], False) collector = LinkCollector(session, scope) prefs = SelectionPreferences(allow_yanked=False) finder = PackageFinder.create(collector, prefs) - yield finder + return finder @pytest.fixture @@ -53,8 +53,8 @@ def preparer(finder: PackageFinder) -> Iterator[RequirementPreparer]: @pytest.fixture -def factory(finder: PackageFinder, preparer: RequirementPreparer) -> Iterator[Factory]: - yield Factory( +def factory(finder: PackageFinder, preparer: RequirementPreparer) -> Factory: + return Factory( finder=finder, preparer=preparer, make_install_req=install_req_from_line, @@ -68,8 +68,8 @@ def factory(finder: PackageFinder, preparer: RequirementPreparer) -> Iterator[Fa @pytest.fixture -def provider(factory: Factory) -> Iterator[PipProvider]: - yield PipProvider( +def provider(factory: Factory) -> PipProvider: + return PipProvider( factory=factory, constraints={}, ignore_dependencies=False, diff --git a/tests/unit/resolution_resolvelib/test_requirement.py b/tests/unit/resolution_resolvelib/test_requirement.py index b7b0395b037..436081b1d8f 100644 --- a/tests/unit/resolution_resolvelib/test_requirement.py +++ b/tests/unit/resolution_resolvelib/test_requirement.py @@ -1,6 +1,6 @@ import os from pathlib import Path -from typing import Iterator, List, Tuple +from typing import List, Tuple import pytest from pip._vendor.resolvelib import BaseReporter, Resolver @@ -32,7 +32,7 @@ def _is_satisfied_by(requirement: Requirement, candidate: Candidate) -> bool: @pytest.fixture -def test_cases(data: TestData) -> Iterator[List[Tuple[str, str, int]]]: +def test_cases(data: TestData) -> List[Tuple[str, str, int]]: def _data_file(name: str) -> Path: return data.packages.joinpath(name) @@ -61,7 +61,7 @@ def data_url(name: str) -> str: # TODO: directory, editables ] - yield test_cases + return test_cases def test_new_resolver_requirement_has_name( diff --git a/tests/unit/resolution_resolvelib/test_resolver.py b/tests/unit/resolution_resolvelib/test_resolver.py index 87c2b5f3533..b1525a20a56 100644 --- a/tests/unit/resolution_resolvelib/test_resolver.py +++ b/tests/unit/resolution_resolvelib/test_resolver.py @@ -16,7 +16,7 @@ ) -@pytest.fixture() +@pytest.fixture def resolver(preparer: RequirementPreparer, finder: PackageFinder) -> Resolver: resolver = Resolver( preparer=preparer, diff --git a/tests/unit/test_collector.py b/tests/unit/test_collector.py index 89da25b73d8..882f82ae4fe 100644 --- a/tests/unit/test_collector.py +++ b/tests/unit/test_collector.py @@ -259,7 +259,7 @@ def test_get_simple_response_dont_log_clear_text_password( @pytest.mark.parametrize( - ("path", "expected"), + "path, expected", [ # Test a character that needs quoting. ("a b", "a%20b"), @@ -299,7 +299,7 @@ def test_clean_url_path(path: str, expected: str, is_local_path: bool) -> None: @pytest.mark.parametrize( - ("path", "expected"), + "path, expected", [ # Test a VCS path with a Windows drive letter and revision. pytest.param( @@ -322,7 +322,7 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None: @pytest.mark.parametrize( - ("url", "clean_url"), + "url, clean_url", [ # URL with hostname and port. Port separator should not be quoted. ( @@ -880,11 +880,9 @@ def test_collect_sources__file_expand_dir(data: TestData) -> None: project_name="", candidates_from_page=None, # type: ignore[arg-type] ) - assert ( - not sources.index_urls - and len(sources.find_links) == 1 - and isinstance(sources.find_links[0], _FlatDirectorySource) - ), ( + assert not sources.index_urls + assert len(sources.find_links) == 1 + assert isinstance(sources.find_links[0], _FlatDirectorySource), ( "Directory source should have been found " f"at find-links url: {data.find_links}" ) @@ -909,10 +907,10 @@ def test_collect_sources__file_not_find_link(data: TestData) -> None: # Shouldn't be used. candidates_from_page=None, # type: ignore[arg-type] ) - assert ( - not sources.find_links - and len(sources.index_urls) == 1 - and isinstance(sources.index_urls[0], _IndexDirectorySource) + assert not sources.find_links + assert len(sources.index_urls) == 1 + assert isinstance( + sources.index_urls[0], _IndexDirectorySource ), "Directory specified as index should be treated as a page" @@ -934,9 +932,8 @@ def test_collect_sources__non_existing_path() -> None: project_name=None, # type: ignore[arg-type] candidates_from_page=None, # type: ignore[arg-type] ) - assert not sources.index_urls and sources.find_links == [ - None - ], "Nothing should have been found" + assert not sources.index_urls + assert sources.find_links == [None], "Nothing should have been found" def check_links_include(links: List[Link], names: List[str]) -> None: @@ -1208,4 +1205,5 @@ def test_metadata_file_info_parsing_html( page_url = "dummy_for_comes_from" base_url = "https://index.url/simple" link = Link.from_element(attribs, page_url, base_url) - assert link is not None and link.metadata_file_data == expected + assert link is not None + assert link.metadata_file_data == expected diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py index 6510b569e5f..12a17dcd1f3 100644 --- a/tests/unit/test_exceptions.py +++ b/tests/unit/test_exceptions.py @@ -500,7 +500,7 @@ def fake_getlocale(category: int) -> Tuple[Optional[str], Optional[str]]: monkeypatch.setattr(locale, "getlocale", fake_getlocale) - @pytest.fixture() + @pytest.fixture def marker(self, tmp_path: pathlib.Path) -> pathlib.Path: marker = tmp_path.joinpath("EXTERNALLY-MANAGED") marker.touch() diff --git a/tests/unit/test_index.py b/tests/unit/test_index.py index 78837b94e8b..d02c70b260e 100644 --- a/tests/unit/test_index.py +++ b/tests/unit/test_index.py @@ -819,7 +819,7 @@ def test_make_candidate_evaluator( @pytest.mark.parametrize( - ("fragment", "canonical_name", "expected"), + "fragment, canonical_name, expected", [ # Trivial. ("pip-18.0", "pip", 3), @@ -851,7 +851,7 @@ def test_find_name_version_sep( @pytest.mark.parametrize( - ("fragment", "canonical_name"), + "fragment, canonical_name", [ # A dash must follow the package name. ("zope.interface4.5.0", "zope-interface"), @@ -868,7 +868,7 @@ def test_find_name_version_sep_failure(fragment: str, canonical_name: str) -> No @pytest.mark.parametrize( - ("fragment", "canonical_name", "expected"), + "fragment, canonical_name, expected", [ # Trivial. ("pip-18.0", "pip", "18.0"), diff --git a/tests/unit/test_network_auth.py b/tests/unit/test_network_auth.py index 5c12d870156..86f01e436c0 100644 --- a/tests/unit/test_network_auth.py +++ b/tests/unit/test_network_auth.py @@ -11,7 +11,7 @@ from tests.lib.requests_mocks import MockConnection, MockRequest, MockResponse -@pytest.fixture(scope="function", autouse=True) +@pytest.fixture(autouse=True) def reset_keyring() -> Iterable[None]: yield None # Reset the state of the module between tests @@ -20,7 +20,7 @@ def reset_keyring() -> Iterable[None]: @pytest.mark.parametrize( - ["input_url", "url", "username", "password"], + "input_url, url, username, password", [ ( "http://user%40email.com:password@example.com/path", @@ -177,7 +177,7 @@ def set_password(self, system: str, username: str, password: str) -> None: @pytest.mark.parametrize( "url, expect", - ( + [ ("http://example.com/path1", (None, None)), # path1 URLs will be resolved by netloc ("http://user@example.com/path3", ("user", "user!netloc")), @@ -185,7 +185,7 @@ def set_password(self, system: str, username: str, password: str) -> None: # path2 URLs will be resolved by index URL ("http://example.com/path2/path3", (None, None)), ("http://foo@example.com/path2/path3", ("foo", "foo!url")), - ), + ], ) def test_keyring_get_password( monkeypatch: pytest.MonkeyPatch, @@ -257,7 +257,7 @@ def test_keyring_get_password_username_in_index( @pytest.mark.parametrize( "response_status, creds, expect_save", - ( + [ (403, ("user", "pass", True), False), ( 200, @@ -269,7 +269,7 @@ def test_keyring_get_password_username_in_index( ("user", "pass", False), False, ), - ), + ], ) def test_keyring_set_password( monkeypatch: pytest.MonkeyPatch, @@ -291,7 +291,7 @@ def should_save_password_to_keyring(*a: Any) -> bool: # when _prompt_for_password indicates not to save, we should # never call this function def should_save_password_to_keyring(*a: Any) -> bool: - assert False, "_should_save_password_to_keyring should not be called" + pytest.fail("_should_save_password_to_keyring should not be called") monkeypatch.setattr( auth, "_should_save_password_to_keyring", should_save_password_to_keyring @@ -333,7 +333,7 @@ def __init__(self, username: str, password: str) -> None: self.password = password def get_password(self, system: str, username: str) -> None: - assert False, "get_password should not ever be called" + pytest.fail("get_password should not ever be called") def get_credential(self, system: str, username: str) -> Optional[Credential]: if system == "http://example.com/path2/": @@ -345,11 +345,11 @@ def get_credential(self, system: str, username: str) -> Optional[Credential]: @pytest.mark.parametrize( "url, expect", - ( + [ ("http://example.com/path1", ("username", "netloc")), ("http://example.com/path2/path3", ("username", "url")), ("http://user2@example.com/path2/path3", ("username", "url")), - ), + ], ) def test_keyring_get_credential( monkeypatch: pytest.MonkeyPatch, url: str, expect: Tuple[str, str] @@ -442,7 +442,7 @@ def check_returncode(self) -> None: @pytest.mark.parametrize( "url, expect", - ( + [ ("http://example.com/path1", (None, None)), # path1 URLs will be resolved by netloc ("http://user@example.com/path3", ("user", "user!netloc")), @@ -450,7 +450,7 @@ def check_returncode(self) -> None: # path2 URLs will be resolved by index URL ("http://example.com/path2/path3", (None, None)), ("http://foo@example.com/path2/path3", ("foo", "foo!url")), - ), + ], ) def test_keyring_cli_get_password( monkeypatch: pytest.MonkeyPatch, @@ -472,7 +472,7 @@ def test_keyring_cli_get_password( @pytest.mark.parametrize( "response_status, creds, expect_save", - ( + [ (403, ("user", "pass", True), False), ( 200, @@ -484,7 +484,7 @@ def test_keyring_cli_get_password( ("user", "pass", False), False, ), - ), + ], ) def test_keyring_cli_set_password( monkeypatch: pytest.MonkeyPatch, @@ -507,7 +507,7 @@ def should_save_password_to_keyring(*a: Any) -> bool: # when _prompt_for_password indicates not to save, we should # never call this function def should_save_password_to_keyring(*a: Any) -> bool: - assert False, "_should_save_password_to_keyring should not be called" + pytest.fail("_should_save_password_to_keyring should not be called") monkeypatch.setattr( auth, "_should_save_password_to_keyring", should_save_password_to_keyring diff --git a/tests/unit/test_network_cache.py b/tests/unit/test_network_cache.py index f1ed1f7edc1..b43b36cd897 100644 --- a/tests/unit/test_network_cache.py +++ b/tests/unit/test_network_cache.py @@ -1,6 +1,5 @@ import os from pathlib import Path -from typing import Iterator from unittest.mock import Mock import pytest @@ -10,11 +9,11 @@ from tests.lib.filesystem import chmod -@pytest.fixture(scope="function") -def cache_tmpdir(tmpdir: Path) -> Iterator[Path]: +@pytest.fixture +def cache_tmpdir(tmpdir: Path) -> Path: cache_dir = tmpdir.joinpath("cache") cache_dir.mkdir(parents=True) - yield cache_dir + return cache_dir class TestSafeFileCache: diff --git a/tests/unit/test_network_lazy_wheel.py b/tests/unit/test_network_lazy_wheel.py index 79e86321793..356387d2bba 100644 --- a/tests/unit/test_network_lazy_wheel.py +++ b/tests/unit/test_network_lazy_wheel.py @@ -1,7 +1,7 @@ from typing import Iterator +import pytest from pip._vendor.packaging.version import Version -from pytest import fixture, mark, raises from pip._internal.exceptions import InvalidWheel from pip._internal.network.lazy_wheel import ( @@ -25,12 +25,12 @@ } -@fixture +@pytest.fixture def session() -> PipSession: return PipSession() -@fixture +@pytest.fixture def mypy_whl_no_range(mock_server: MockServer, shared_data: TestData) -> Iterator[str]: mypy_whl = shared_data.packages / "mypy-0.782-py3-none-any.whl" mock_server.set_responses([file_response(mypy_whl)]) @@ -40,7 +40,7 @@ def mypy_whl_no_range(mock_server: MockServer, shared_data: TestData) -> Iterato mock_server.stop() -@mark.network +@pytest.mark.network def test_dist_from_wheel_url(session: PipSession) -> None: """Test if the acquired distribution contain correct information.""" dist = dist_from_wheel_url("mypy", MYPY_0_782_WHL, session) @@ -55,12 +55,12 @@ def test_dist_from_wheel_url_no_range( session: PipSession, mypy_whl_no_range: str ) -> None: """Test handling when HTTP range requests are not supported.""" - with raises(HTTPRangeRequestUnsupported): + with pytest.raises(HTTPRangeRequestUnsupported): dist_from_wheel_url("mypy", mypy_whl_no_range, session) -@mark.network +@pytest.mark.network def test_dist_from_wheel_url_not_zip(session: PipSession) -> None: """Test handling with the given URL does not point to a ZIP.""" - with raises(InvalidWheel): + with pytest.raises(InvalidWheel): dist_from_wheel_url("python", "https://www.python.org/", session) diff --git a/tests/unit/test_network_utils.py b/tests/unit/test_network_utils.py index 380d5741ff6..1b198c166fc 100644 --- a/tests/unit/test_network_utils.py +++ b/tests/unit/test_network_utils.py @@ -6,7 +6,7 @@ @pytest.mark.parametrize( - ("status_code", "error_type"), + "status_code, error_type", [ (401, "Client Error"), (501, "Server Error"), diff --git a/tests/unit/test_options.py b/tests/unit/test_options.py index 53074fe047c..aee64ccc932 100644 --- a/tests/unit/test_options.py +++ b/tests/unit/test_options.py @@ -68,7 +68,7 @@ def test_env_override_default_int(self, monkeypatch: pytest.MonkeyPatch) -> None options, args = cast(Tuple[Values, List[str]], main(["fake"])) assert options.timeout == -1 - @pytest.mark.parametrize("values", (["F1"], ["F1", "F2"])) + @pytest.mark.parametrize("values", [["F1"], ["F1", "F2"]]) def test_env_override_default_append( self, values: List[str], monkeypatch: pytest.MonkeyPatch ) -> None: @@ -80,7 +80,7 @@ def test_env_override_default_append( options, args = cast(Tuple[Values, List[str]], main(["fake"])) assert options.find_links == values - @pytest.mark.parametrize("choices", (["w"], ["s", "w"])) + @pytest.mark.parametrize("choices", [["w"], ["s", "w"]]) def test_env_override_default_choice( self, choices: List[str], monkeypatch: pytest.MonkeyPatch ) -> None: @@ -92,7 +92,7 @@ def test_env_override_default_choice( options, args = cast(Tuple[Values, List[str]], main(["fake"])) assert options.exists_action == choices - @pytest.mark.parametrize("name", ("PIP_LOG_FILE", "PIP_LOCAL_LOG")) + @pytest.mark.parametrize("name", ["PIP_LOG_FILE", "PIP_LOCAL_LOG"]) def test_env_alias_override_default( self, name: str, monkeypatch: pytest.MonkeyPatch ) -> None: @@ -316,7 +316,7 @@ def tmpconfig(option: str, value: Any, section: str = "global") -> Iterator[str] class TestCountOptions(AddFakeCommandMixin): - @pytest.mark.parametrize("option", ("verbose", "quiet")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) @pytest.mark.parametrize("value", range(4)) def test_cli_long(self, option: str, value: int) -> None: flags = [f"--{option}"] * value @@ -325,7 +325,7 @@ def test_cli_long(self, option: str, value: int) -> None: opt2, args2 = cast(Tuple[Values, List[str]], main(["fake"] + flags)) assert getattr(opt1, option) == getattr(opt2, option) == value - @pytest.mark.parametrize("option", ("verbose", "quiet")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) @pytest.mark.parametrize("value", range(1, 4)) def test_cli_short(self, option: str, value: int) -> None: flag = "-" + option[0] * value @@ -334,7 +334,7 @@ def test_cli_short(self, option: str, value: int) -> None: opt2, args2 = cast(Tuple[Values, List[str]], main(["fake", flag])) assert getattr(opt1, option) == getattr(opt2, option) == value - @pytest.mark.parametrize("option", ("verbose", "quiet")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) @pytest.mark.parametrize("value", range(4)) def test_env_var( self, option: str, value: int, monkeypatch: pytest.MonkeyPatch @@ -344,7 +344,7 @@ def test_env_var( options, args = cast(Tuple[Values, List[str]], main(["fake"])) assert getattr(options, option) == value - @pytest.mark.parametrize("option", ("verbose", "quiet")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) @pytest.mark.parametrize("value", range(3)) def test_env_var_integrate_cli( self, option: str, value: int, monkeypatch: pytest.MonkeyPatch @@ -354,8 +354,8 @@ def test_env_var_integrate_cli( options, args = cast(Tuple[Values, List[str]], main(["fake", "--" + option])) assert getattr(options, option) == value + 1 - @pytest.mark.parametrize("option", ("verbose", "quiet")) - @pytest.mark.parametrize("value", (-1, "foobar")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) + @pytest.mark.parametrize("value", [-1, "foobar"]) def test_env_var_invalid( self, option: str, @@ -368,8 +368,8 @@ def test_env_var_invalid( main(["fake"]) # Undocumented, support for backward compatibility - @pytest.mark.parametrize("option", ("verbose", "quiet")) - @pytest.mark.parametrize("value", ("no", "false")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) + @pytest.mark.parametrize("value", ["no", "false"]) def test_env_var_false( self, option: str, value: str, monkeypatch: pytest.MonkeyPatch ) -> None: @@ -379,8 +379,8 @@ def test_env_var_false( assert getattr(options, option) == 0 # Undocumented, support for backward compatibility - @pytest.mark.parametrize("option", ("verbose", "quiet")) - @pytest.mark.parametrize("value", ("yes", "true")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) + @pytest.mark.parametrize("value", ["yes", "true"]) def test_env_var_true( self, option: str, value: str, monkeypatch: pytest.MonkeyPatch ) -> None: @@ -389,7 +389,7 @@ def test_env_var_true( options, args = cast(Tuple[Values, List[str]], main(["fake"])) assert getattr(options, option) == 1 - @pytest.mark.parametrize("option", ("verbose", "quiet")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) @pytest.mark.parametrize("value", range(4)) def test_config_file( self, option: str, value: int, monkeypatch: pytest.MonkeyPatch @@ -400,7 +400,7 @@ def test_config_file( options, args = cast(Tuple[Values, List[str]], main(["fake"])) assert getattr(options, option) == value - @pytest.mark.parametrize("option", ("verbose", "quiet")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) @pytest.mark.parametrize("value", range(3)) def test_config_file_integrate_cli( self, option: str, value: int, monkeypatch: pytest.MonkeyPatch @@ -413,8 +413,8 @@ def test_config_file_integrate_cli( ) assert getattr(options, option) == value + 1 - @pytest.mark.parametrize("option", ("verbose", "quiet")) - @pytest.mark.parametrize("value", (-1, "foobar")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) + @pytest.mark.parametrize("value", [-1, "foobar"]) def test_config_file_invalid( self, option: str, @@ -428,8 +428,8 @@ def test_config_file_invalid( main(["fake"]) # Undocumented, support for backward compatibility - @pytest.mark.parametrize("option", ("verbose", "quiet")) - @pytest.mark.parametrize("value", ("no", "false")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) + @pytest.mark.parametrize("value", ["no", "false"]) def test_config_file_false( self, option: str, value: str, monkeypatch: pytest.MonkeyPatch ) -> None: @@ -440,8 +440,8 @@ def test_config_file_false( assert getattr(options, option) == 0 # Undocumented, support for backward compatibility - @pytest.mark.parametrize("option", ("verbose", "quiet")) - @pytest.mark.parametrize("value", ("yes", "true")) + @pytest.mark.parametrize("option", ["verbose", "quiet"]) + @pytest.mark.parametrize("value", ["yes", "true"]) def test_config_file_true( self, option: str, value: str, monkeypatch: pytest.MonkeyPatch ) -> None: @@ -590,7 +590,7 @@ def test_venv_config_file_found(self, monkeypatch: pytest.MonkeyPatch) -> None: @pytest.mark.parametrize( "args, expect", - ( + [ ([], None), (["--global"], "global"), (["--site"], "site"), @@ -598,7 +598,7 @@ def test_venv_config_file_found(self, monkeypatch: pytest.MonkeyPatch) -> None: (["--global", "--user"], PipError), (["--global", "--site"], PipError), (["--global", "--site", "--user"], PipError), - ), + ], ) def test_config_file_options( self, diff --git a/tests/unit/test_pep517.py b/tests/unit/test_pep517.py index 5eefbf4e77c..b9fcd9d2137 100644 --- a/tests/unit/test_pep517.py +++ b/tests/unit/test_pep517.py @@ -1,6 +1,7 @@ import os from pathlib import Path from textwrap import dedent +from typing import Tuple import pytest @@ -10,7 +11,7 @@ @pytest.mark.parametrize( - ("source", "expected"), + "source, expected", [ ("pep517_setup_and_pyproject", True), ("pep517_setup_only", False), @@ -45,7 +46,7 @@ def test_use_pep517_rejects_setup_cfg_only(shared_data: TestData) -> None: @pytest.mark.parametrize( - ("source", "msg"), + "source, msg", [ ("pep517_setup_and_pyproject", "specifies a build backend"), ("pep517_pyproject_only", "does not have a setup.py"), @@ -71,14 +72,14 @@ def test_disabling_pep517_invalid(shared_data: TestData, source: str, msg: str) @pytest.mark.parametrize( - ("spec",), [("./foo",), ("git+https://example.com/pkg@dev#egg=myproj",)] + "spec", [("./foo",), ("git+https://example.com/pkg@dev#egg=myproj",)] ) -def test_pep517_parsing_checks_requirements(tmpdir: Path, spec: str) -> None: +def test_pep517_parsing_checks_requirements(tmpdir: Path, spec: Tuple[str]) -> None: tmpdir.joinpath("pyproject.toml").write_text( dedent( f""" [build-system] - requires = [{spec!r}] + requires = [{spec[0]!r}] build-backend = "foo" """ ) diff --git a/tests/unit/test_pyproject_config.py b/tests/unit/test_pyproject_config.py index c7e46956055..d385cfb515d 100644 --- a/tests/unit/test_pyproject_config.py +++ b/tests/unit/test_pyproject_config.py @@ -6,7 +6,7 @@ @pytest.mark.parametrize( - ("command", "expected"), + "command, expected", [ ("install", True), ("wheel", True), @@ -39,7 +39,7 @@ def test_set_config_empty_value() -> None: @pytest.mark.parametrize( - ("passed", "expected"), + "passed, expected", [ (["x=hello", "x=world"], {"x": ["hello", "world"]}), (["x=hello", "x=world", "x=other"], {"x": ["hello", "world", "other"]}), diff --git a/tests/unit/test_req_file.py b/tests/unit/test_req_file.py index f4f98b1901c..236b666fb34 100644 --- a/tests/unit/test_req_file.py +++ b/tests/unit/test_req_file.py @@ -519,7 +519,7 @@ def get_file_content( return None, "-r reqs.txt" elif filename == "http://me.com/me/reqs.txt": return None, req_name - assert False, f"Unexpected file requested {filename}" + pytest.fail(f"Unexpected file requested {filename}") monkeypatch.setattr( pip._internal.req.req_file, "get_file_content", get_file_content @@ -588,7 +588,7 @@ def get_file_content( return None, f"-r {nested_req_file}" elif filename == nested_req_file: return None, req_name - assert False, f"Unexpected file requested {filename}" + pytest.fail(f"Unexpected file requested {filename}") monkeypatch.setattr( pip._internal.req.req_file, "get_file_content", get_file_content diff --git a/tests/unit/test_req_uninstall.py b/tests/unit/test_req_uninstall.py index b61babc343a..0523ffd7a07 100644 --- a/tests/unit/test_req_uninstall.py +++ b/tests/unit/test_req_uninstall.py @@ -380,8 +380,10 @@ def test_commit_symlinks(self, tmpdir: Path) -> None: # stash removed, links removed for stashed_path in stashed_paths: assert not os.path.lexists(stashed_path) - assert not os.path.lexists(dirlink) and not os.path.isdir(dirlink) - assert not os.path.lexists(filelink) and not os.path.isfile(filelink) + assert not os.path.lexists(dirlink) + assert not os.path.isdir(dirlink) + assert not os.path.lexists(filelink) + assert not os.path.isfile(filelink) # link targets untouched assert os.path.isdir(adir) @@ -412,8 +414,10 @@ def test_rollback_symlinks(self, tmpdir: Path) -> None: # stash removed, links restored for stashed_path in stashed_paths: assert not os.path.lexists(stashed_path) - assert os.path.lexists(dirlink) and os.path.isdir(dirlink) - assert os.path.lexists(filelink) and os.path.isfile(filelink) + assert os.path.lexists(dirlink) + assert os.path.isdir(dirlink) + assert os.path.lexists(filelink) + assert os.path.isfile(filelink) # link targets untouched assert os.path.isdir(adir) diff --git a/tests/unit/test_self_check_outdated.py b/tests/unit/test_self_check_outdated.py index 99a556e8ac7..605d9182a09 100644 --- a/tests/unit/test_self_check_outdated.py +++ b/tests/unit/test_self_check_outdated.py @@ -16,7 +16,7 @@ @pytest.mark.parametrize( - ["key", "expected"], + "key, expected", [ ( "/hello/world/venv", @@ -59,7 +59,7 @@ def test_pip_self_version_check_calls_underlying_implementation( @pytest.mark.parametrize( - [ + [ # noqa: PT006 - String representation is too long "installed_version", "remote_version", "stored_version", diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index aa9e7fd56c2..d1e64262de2 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -559,7 +559,7 @@ def test_normalize_version_info( class TestGetProg: @pytest.mark.parametrize( - ("argv", "executable", "expected"), + "argv, executable, expected", [ ("/usr/bin/pip", "", "pip"), ("-c", "/usr/bin/python", "/usr/bin/python -m pip"), @@ -860,7 +860,7 @@ def test_hide_url() -> None: assert hidden_url.secret == "https://user:password@example.com" -@pytest.fixture() +@pytest.fixture def patch_deprecation_check_version() -> Iterator[None]: # We do this, so that the deprecation tests are easier to write. import pip._internal.utils.deprecation as d @@ -1061,7 +1061,7 @@ def test_format_size(size: int, expected: str) -> None: @pytest.mark.parametrize( - ("rows", "table", "sizes"), + "rows, table, sizes", [ ([], [], []), ( diff --git a/tests/unit/test_utils_retry.py b/tests/unit/test_utils_retry.py index 74abce6f66f..4331d0e2604 100644 --- a/tests/unit/test_utils_retry.py +++ b/tests/unit/test_utils_retry.py @@ -42,13 +42,9 @@ def _raise_error() -> NoReturn: function = Mock(wraps=_raise_error) wrapped = retry(wait=0, stop_after_delay=0.01)(function) - try: + with pytest.raises(RuntimeError) as exc_info: wrapped() - except Exception as e: - assert isinstance(e, RuntimeError) - assert e is errors[-1] - else: - assert False, "unexpected return" + assert exc_info.value is errors[-1] assert function.call_count > 1, "expected at least one retry" diff --git a/tests/unit/test_utils_subprocess.py b/tests/unit/test_utils_subprocess.py index 5f0c16595a7..65e7d6fdca9 100644 --- a/tests/unit/test_utils_subprocess.py +++ b/tests/unit/test_utils_subprocess.py @@ -39,7 +39,7 @@ def test_format_command_args(args: CommandArgs, expected: str) -> None: @pytest.mark.parametrize( - ("stdout_only", "expected"), + "stdout_only, expected", [ (True, ("out\n", "out\r\n")), (False, ("out\nerr\n", "out\r\nerr\r\n", "err\nout\n", "err\r\nout\r\n")), @@ -312,7 +312,7 @@ def test_info_logging_with_show_stdout_true( ) @pytest.mark.parametrize( - ("exit_status", "show_stdout", "extra_ok_returncodes", "log_level", "expected"), + "exit_status, show_stdout, extra_ok_returncodes, log_level, expected", [ # The spinner should show here because show_stdout=False means # the subprocess should get logged at DEBUG level, but the passed diff --git a/tests/unit/test_utils_unpacking.py b/tests/unit/test_utils_unpacking.py index efccbdccb0d..e0db5c4ba4a 100644 --- a/tests/unit/test_utils_unpacking.py +++ b/tests/unit/test_utils_unpacking.py @@ -198,7 +198,7 @@ def test_unpack_tar_filter(self) -> None: assert "is outside the destination" in str(e.value) @pytest.mark.parametrize( - ("input_prefix", "unpack_prefix"), + "input_prefix, unpack_prefix", [ ("", ""), ("dir/", ""), # pip ignores a common leading directory diff --git a/tests/unit/test_vcs.py b/tests/unit/test_vcs.py index a868c9f704d..13ef42fc43f 100644 --- a/tests/unit/test_vcs.py +++ b/tests/unit/test_vcs.py @@ -61,7 +61,7 @@ def test_rev_options_repr() -> None: @pytest.mark.parametrize( - ("vc_class", "expected1", "expected2", "kwargs"), + "vc_class, expected1, expected2, kwargs", [ # First check VCS-specific RevOptions behavior. (Bazaar, [], ["-r", "123"], {}), @@ -291,14 +291,14 @@ def test_git_resolve_revision_not_found_warning( @pytest.mark.parametrize( "rev_name,result", - ( + [ ("5547fa909e83df8bd743d3978d6667497983a4b7", True), ("5547fa909", False), ("5678", False), ("abc123", False), ("foo", False), (None, False), - ), + ], ) @mock.patch("pip._internal.vcs.git.Git.get_revision") def test_git_is_commit_id_equal( @@ -599,7 +599,7 @@ def test_get_git_version() -> None: @pytest.mark.parametrize( - ("version", "expected"), + "version, expected", [ ("git version 2.17", (2, 17)), ("git version 2.18.1", (2, 18)),