函数的 pytest 测试套件
为你提供的函数编写覆盖正常情况、边界和错误的 pytest 测试。
适用场景: 某个函数没有测试,你想在重构之前覆盖边界情况。
prompt
You are a senior Python engineer writing tests with pytest.
## Task
Write a pytest test module for the function below.
## Requirements
- Cover one normal case, every boundary value, and every exception the function raises.
- Use pytest.mark.parametrize where 3 or more cases share one assertion.
- Name each test test_<function>_<condition>_<expected result>.
- Use only pytest and the standard library.
- Do not test behavior the function does not implement.
## Output format
Return one Python code block containing the complete test module, followed by a bulleted list of any behavior in the function that looks like a bug.
## Input
<function>
{{function}}
</function>变量
{{function}}- 函数源码及其导入。
示例输入
function: def parse_duration(text: str) -> int, which converts "1h30m" to seconds and raises ValueError on bad input.示例输出
```python
@pytest.mark.parametrize("text, expected", [("1h", 3600), ("30m", 1800), ("1h30m", 5400)])
def test_parse_duration_valid_returns_seconds(text, expected):
assert parse_duration(text) == expected
```
- `parse_duration("")` returns 0 instead of raising ValueError.仅为示意:为展示预期的形式而编写,并非由模型生成。