run test suite on the implementation

This commit is contained in:
Sirui Huang 2024-04-28 20:30:28 -04:00
parent ea6ddbc870
commit 66d9e3b364
6 changed files with 36 additions and 26 deletions

View File

@ -1645,7 +1645,7 @@ class Config:
elif type == "bool":
return _strtobool(str(value).strip())
elif type == "int":
return int(value)
return int(str(value).strip())
elif type == "string":
return value
elif type is None:

View File

@ -215,7 +215,16 @@ class Parser:
The value of ini-variables can be retrieved via a call to
:py:func:`config.getini(name) <pytest.Config.getini>`.
"""
assert type in (None, "string", "paths", "pathlist", "args", "linelist", "bool", "int")
assert type in (
None,
"string",
"paths",
"pathlist",
"args",
"linelist",
"bool",
"int",
)
if default is NOT_SET:
default = get_ini_default_for_type(type)
@ -224,7 +233,9 @@ class Parser:
def get_ini_default_for_type(
type: Optional[Literal["string", "paths", "pathlist", "args", "linelist", "bool", "int"]],
type: Optional[
Literal["string", "paths", "pathlist", "args", "linelist", "bool", "int"]
],
) -> Any:
"""
Used by addini to get the default value for a given ini-option type, when

View File

@ -846,11 +846,20 @@ class LoggingPlugin:
@hookimpl(wrapper=True)
def pytest_runtest_setup(self, item: nodes.Item) -> Generator[None, None, None]:
if self.log_file_verbose and int(self.log_file_verbose) >= 1:
old_log_file_formatter = self.log_file_handler.formatter
self.log_file_handler.setFormatter(logging.Formatter())
self.log_file_handler.emit(logging.LogRecord('N/A', logging.INFO, 'N/A', 0, f"Running at {item.nodeid}", None, None))
self.log_file_handler.emit(
logging.LogRecord(
"N/A",
logging.INFO,
"N/A",
0,
f"Running at {item.nodeid}",
None,
None,
)
)
self.log_file_handler.setFormatter(old_log_file_formatter)
self.log_cli_handler.set_when("setup")

View File

@ -1,3 +1,2 @@
def add(a, b):
def add(a: int, b: int) -> int:
return a + b

View File

@ -1,7 +1,8 @@
import pytest
@pytest.mark.parametrize("arg1, arg2", [(1, 1)])
def test_parametrization(arg1, arg2):
def test_parametrization(arg1: int, arg2: int) -> None:
assert arg1 == arg2
assert arg1 + 1 == arg2 + 1
@ -12,5 +13,4 @@ def test_parametrization(arg1, arg2):
# The error message lives in this path: pytest/src/_pytest/python.py
# ("arg1", "arg2"), and "arg1, arg2" works, but cannot put in default parameters as normal function

View File

@ -1,22 +1,13 @@
# test_math_operations.py
import pytest
import add_function
import pytest
result_index = [(1, 2, 3), (-1, 1, 0), (0, 0, 0), (5, -3, 2), (1, 1, 2)]
result_index = [
(1, 2, 3),
(-1, 1, 0),
(0, 0, 0),
(5, -3, 2),
(1, 1, 2)
]
@pytest.mark.parametrize("a, b, expected_result", result_index)
def test_add(a, b, expected_result):
def test_add(a: int, b: int, expected_result: int) -> None:
assert add_function.add(a, b) == expected_result