Skip to content

Commit b302d31

Browse files
committed
Fix explicit checks
1 parent b28195f commit b302d31

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/_pytest/config/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,10 +1647,6 @@ def _getini(self, name: str):
16471647
if self.inipath is not None
16481648
else self.invocation_params.dir
16491649
)
1650-
if not isinstance(value, (str, Sequence)):
1651-
raise TypeError(
1652-
f"Expected str or sequence for option {name} of type str/list, but got: {value!r}"
1653-
) from None
16541650
input_values = shlex.split(value) if isinstance(value, str) else value
16551651
return [dp / x for x in input_values]
16561652
elif type == "args":
@@ -1665,15 +1661,15 @@ def _getini(self, name: str):
16651661
elif type == "string":
16661662
return value
16671663
elif type == "int":
1668-
if not isinstance(value, (str, int)):
1664+
if not isinstance(value, str):
16691665
raise TypeError(
1670-
f"Expected str or int for option {name} of type integer, but got: {value!r}"
1666+
f"Expected an int string for option {name} of type integer, but got: {value!r}"
16711667
) from None
16721668
return int(value)
16731669
elif type == "float":
1674-
if not isinstance(value, (str, float)):
1670+
if not isinstance(value, str):
16751671
raise TypeError(
1676-
f"Expected str or float for option {name} of type float, but got: {value!r}"
1672+
f"Expected a float string for option {name} of type float, but got: {value!r}"
16771673
) from None
16781674
return float(value)
16791675
elif type is None:

testing/test_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,9 @@ def pytest_addoption(parser):
880880
"""
881881
)
882882
config = pytester.parseconfig()
883-
with pytest.raises(TypeError, match="Expected str or int for option ini_param"):
883+
with pytest.raises(
884+
TypeError, match="Expected an int string for option ini_param"
885+
):
884886
_ = config.getini("ini_param")
885887

886888
@pytest.mark.parametrize("str_val, float_val", [("10.5", 10.5), ("no-ini", 2.2)])
@@ -918,7 +920,7 @@ def pytest_addoption(parser):
918920
)
919921
config = pytester.parseconfig()
920922
with pytest.raises(
921-
TypeError, match="Expected str or float for option ini_param"
923+
TypeError, match="Expected a float string for option ini_param"
922924
):
923925
_ = config.getini("ini_param")
924926

0 commit comments

Comments
 (0)