Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce ruff/flake8-pytest-style rules (PT) #4783

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg_resources/tests/test_pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def test_distribution_version_missing(
metadata_path = os.path.join(dist_dir, expected_filename)

# Now check the exception raised when the "version" attribute is accessed.
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError, match="xxxxx") as excinfo:
dist.version

err = str(excinfo.value)
Expand Down Expand Up @@ -289,7 +289,7 @@ def test_distribution_version_missing_undetected_path():
# Create a Distribution object with no metadata argument, which results
# in an empty metadata provider.
dist = Distribution('/foo')
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError, match="xxxxx") as excinfo:
dist.version

msg, dist = excinfo.value.args
Expand Down
22 changes: 11 additions & 11 deletions pkg_resources/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def testParse(self):

@pytest.mark.parametrize("reject_spec", reject_specs)
def test_reject_spec(self, reject_spec):
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=reject_spec):
EntryPoint.parse(reject_spec)

def test_printable_name(self):
Expand Down Expand Up @@ -497,9 +497,9 @@ def checkSubMap(self, m):

def testParseList(self):
self.checkSubMap(EntryPoint.parse_group("xyz", self.submap_str))
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
EntryPoint.parse_group("x a", "foo=bar")
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
EntryPoint.parse_group("x", ["foo=baz", "foo=bar"])

def testParseMap(self):
Expand All @@ -509,9 +509,9 @@ def testParseMap(self):
m = EntryPoint.parse_map("[xyz]\n" + self.submap_str)
self.checkSubMap(m['xyz'])
assert list(m.keys()) == ['xyz']
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
EntryPoint.parse_map(["[xyz]", "[xyz]"])
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
EntryPoint.parse_map(self.submap_str)

def testDeprecationWarnings(self):
Expand Down Expand Up @@ -642,7 +642,7 @@ def testSplitting(self):
("d", []),
("q", ["v"]),
]
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
list(pkg_resources.split_sections("[foo"))

def testSafeName(self):
Expand All @@ -667,15 +667,15 @@ def testSimpleRequirements(self):
Requirement('Twisted>=1.2,<2.0')
]
assert Requirement.parse("FooBar==1.99a3") == Requirement("FooBar==1.99a3")
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=r" >=2\.3"):
Requirement.parse(">=2.3")
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
Requirement.parse("x\\")
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
Requirement.parse("x==2 q")
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
Requirement.parse("X==1\nY==2")
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="xxxxx"):
Requirement.parse("#")

def test_requirements_with_markers(self):
Expand Down
10 changes: 7 additions & 3 deletions pkg_resources/tests/test_working_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ def parametrize_test_working_set_resolve(*test_list):
)
)
return pytest.mark.parametrize(
'installed_dists,installable_dists,'
'requirements,replace_conflicting,'
'resolved_dists_or_exception',
(
'installed_dists',
'installable_dists',
'requirements',
'replace_conflicting',
'resolved_dists_or_exception',
),
argvalues,
ids=idlist,
)
Expand Down
2 changes: 0 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ extend-select = [
]
ignore = [
"PERF203", # try-except-in-loop, micro-optimisation with many false-positive. Worth checking but don't block CI
"PT007", # temporarily disabled, TODO: configure and standardize to preference
"PT011", # temporarily disabled, TODO: tighten expected error
"PT012", # pytest-raises-with-multiple-statements, avoid extra dummy methods for a few lines, sometimes we explicitly assert in case of no error
"TRY003", # raise-vanilla-args, avoid multitude of exception classes
"TRY301", # raise-within-try, it's handy
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/config/test_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_no_explicit_content_type_for_missing_extension(tmp_path):

@pytest.mark.parametrize(
("pyproject_text", "expected_maintainers_meta_value"),
(
[
pytest.param(
PEP621_EXAMPLE,
(
Expand All @@ -229,7 +229,7 @@ def test_no_explicit_content_type_for_missing_extension(tmp_path):
),
id='international-email',
),
),
],
)
def test_utf8_maintainer_in_metadata( # issue-3663
expected_maintainers_meta_value,
Expand Down
10 changes: 5 additions & 5 deletions setuptools/tests/config/test_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_all_listed_in_dynamic(self, tmp_path):
assert len(expanded_project["entry-points"]) == 1
assert expanded_project["entry-points"]["other"]["c"] == "mod.c:func [extra]"

@pytest.mark.parametrize("missing_dynamic", ("scripts", "gui-scripts"))
@pytest.mark.parametrize("missing_dynamic", ["scripts", "gui-scripts"])
def test_scripts_not_listed_in_dynamic(self, tmp_path, missing_dynamic):
self.write_entry_points(tmp_path)
dynamic = {"scripts", "gui-scripts", "entry-points"} - {missing_dynamic}
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_dynamic_without_file(self, tmp_path):

@pytest.mark.parametrize(
"example",
(
[
"""
[project]
name = "myproj"
Expand All @@ -297,7 +297,7 @@ def test_dynamic_without_file(self, tmp_path):
[my-tool.that-disrespect.pep518]
value = 42
""",
),
],
)
def test_ignore_unrelated_config(tmp_path, example):
pyproject = tmp_path / "pyproject.toml"
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_invalid_example(tmp_path, example, error_msg):
read_configuration(pyproject)


@pytest.mark.parametrize("config", ("", "[tool.something]\nvalue = 42"))
@pytest.mark.parametrize("config", ["", "[tool.something]\nvalue = 42"])
def test_empty(tmp_path, config):
pyproject = tmp_path / "pyproject.toml"
pyproject.write_text(config, encoding="utf-8")
Expand All @@ -339,7 +339,7 @@ def test_empty(tmp_path, config):
assert read_configuration(pyproject) == {}


@pytest.mark.parametrize("config", ("[project]\nname = 'myproj'\nversion='42'\n",))
@pytest.mark.parametrize("config", ["[project]\nname = 'myproj'\nversion='42'\n"])
def test_include_package_data_by_default(tmp_path, config):
"""Builds with ``pyproject.toml`` should consider ``include-package-data=True`` as
default.
Expand Down
6 changes: 3 additions & 3 deletions setuptools/tests/config/test_setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,9 @@ def test_python_requires_invalid(self, tmpdir):
"""
),
)
with pytest.raises(Exception):
with get_dist(tmpdir) as dist:
dist.parse_config_files()
############# with pytest.raises(Exception):
with get_dist(tmpdir) as dist:
dist.parse_config_files()

def test_cmdclass(self, tmpdir):
module_path = Path(tmpdir, "src/custom_build.py") # auto discovery for src
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_build_wheel(self, build_backend):
modules = [f for f in python_scripts if not f.endswith('setup.py')]
assert len(modules) == 1

@pytest.mark.parametrize('build_type', ('wheel', 'sdist'))
@pytest.mark.parametrize('build_type', ['wheel', 'sdist'])
def test_build_with_existing_file_present(self, build_type, tmpdir_cwd):
# Building a sdist/wheel should still succeed if there's
# already a sdist/wheel in the destination directory.
Expand Down Expand Up @@ -895,7 +895,7 @@ def test_setup_py_file_abspath(self, tmpdir_cwd):
build_backend = self.get_build_backend()
build_backend.build_sdist("temp")

@pytest.mark.parametrize('build_hook', ('build_sdist', 'build_wheel'))
@pytest.mark.parametrize('build_hook', ['build_sdist', 'build_wheel'])
def test_build_with_empty_setuppy(self, build_backend, build_hook):
files = {'setup.py': ''}
path.build(files)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

@pytest.mark.parametrize(
("content", "result"),
(
[
pytest.param(
"Just a single line",
None,
Expand All @@ -62,7 +62,7 @@
"Leading whitespace\nIn\n Multiline comment",
id="remove_leading_whitespace_multiline",
),
),
],
)
def test_rfc822_unescape(content, result):
assert (result or content) == rfc822_unescape(rfc822_escape(content))
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_dist_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_tag_arguments(self, tmp_path):
dist_info = next(tmp_path.glob("*.dist-info"))
assert dist_info.name.startswith("proj-42a")

@pytest.mark.parametrize("keep_egg_info", (False, True))
@pytest.mark.parametrize("keep_egg_info", [False, True])
def test_output_dir(self, tmp_path, keep_egg_info):
config = "[metadata]\nname=proj\nversion=42\n"
(tmp_path / "setup.cfg").write_text(config, encoding="utf-8")
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir):
)
assert eggs == ['dep 1.0']

@pytest.mark.parametrize('with_dependency_links_in_setup_py', (False, True))
@pytest.mark.parametrize('with_dependency_links_in_setup_py', [False, True])
def test_setup_requires_with_find_links_in_setup_cfg(
self, monkeypatch, with_dependency_links_in_setup_py
):
Expand Down
6 changes: 3 additions & 3 deletions setuptools/tests/test_editable_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ def test_nspkg_file_is_unique(self, tmp_path, monkeypatch):

@pytest.mark.parametrize(
"impl",
(
[
"pkg_resources",
# "pkgutil", => does not work
),
],
)
@pytest.mark.parametrize("ns", ("myns.n",))
@pytest.mark.parametrize("ns", ["myns.n"])
def test_namespace_package_importable(
self, venv, tmp_path, ns, impl, editable_opts
):
Expand Down
7 changes: 6 additions & 1 deletion setuptools/tests/test_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,12 @@ def parametrize(*test_list, **format_dict):
)
)
return pytest.mark.parametrize(
'requires,use_setup_cfg,expected_requires,install_cmd_kwargs',
(
'requires',
'use_setup_cfg',
'expected_requires',
'install_cmd_kwargs',
),
argvalues,
ids=idlist,
)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@pytest.mark.parametrize(
('tree', 'pattern', 'matches'),
(
[
('', b'', []),
('', '', []),
(
Expand Down Expand Up @@ -37,7 +37,7 @@
b'*.rst',
(b'CHANGES.rst', b'README.rst'),
),
),
],
)
def test_glob(monkeypatch, tmpdir, tree, pattern, matches):
monkeypatch.chdir(tmpdir)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_exception_resumed(self):
with setuptools.sandbox.ExceptionSaver() as saved_exc:
raise ValueError("details")

with pytest.raises(ValueError) as caught:
with pytest.raises(ValueError, match="details") as caught:
saved_exc.resume()

assert isinstance(caught.value, ValueError)
Expand All @@ -59,7 +59,7 @@ def test_exception_reconstructed(self):
with setuptools.sandbox.ExceptionSaver() as saved_exc:
raise orig_exc

with pytest.raises(ValueError) as caught:
with pytest.raises(ValueError, match="details") as caught:
saved_exc.resume()

assert isinstance(caught.value, ValueError)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def files_for_symlink_in_extension_depends(tmp_path, dep_path):
}

@pytest.mark.parametrize(
"dep_path", ("myheaders/dir/file.h", "myheaders/dir/../dir/file.h")
"dep_path", ["myheaders/dir/file.h", "myheaders/dir/../dir/file.h"]
)
def test_symlink_in_extension_depends(self, monkeypatch, tmp_path, dep_path):
# Given a project with a symlinked dir and a "depends" targeting that dir
Expand Down Expand Up @@ -939,7 +939,7 @@ def files_for_external_path_in_extension_depends(tmp_path, dep_path):
}

@pytest.mark.parametrize(
"dep_path", ("$tmp_path$/external/dir/file.h", "../external/dir/file.h")
"dep_path", ["$tmp_path$/external/dir/file.h", "../external/dir/file.h"]
)
def test_external_path_in_extension_depends(self, monkeypatch, tmp_path, dep_path):
# Given a project with a "depends" targeting an external dir
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def test_wheel_no_dist_dir():
# create an empty zip file
zipfile.ZipFile(wheel_path, 'w').close()
with tempdir() as install_dir:
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=r"\.dist-info not found"):
_check_wheel_install(
wheel_path, install_dir, None, project_name, version, None
)
Expand Down
Loading