Skip to content

Commit b868bba

Browse files
authored
feat(test): add the pytest-cases package and a simple example of how to use it (#873)
1 parent a3e1921 commit b868bba

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ hooks = [
6161
]
6262
# Note that the `custom_exit_code` and `env` plugins may currently be unmaintained.
6363
test = [
64+
"faker ==35.0.0",
6465
"hypothesis >=6.21.0,<6.122.8",
6566
"pytest >=7.2.0,<9.0.0",
67+
"pytest-cases ==3.8.6",
6668
"pytest-custom_exit_code ==0.3.0",
6769
"pytest-cov ==6.0.0",
6870
"pytest-doctestplus ==1.3.0",

tests/test_something.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
"""Test the Something module. Add more tests here, as needed."""
22

3+
import faker
34
from hypothesis import given, strategies
5+
from pytest_cases import parametrize_with_cases
46

57
from package.something import Something
68

79

810
@given(strategies.booleans())
9-
def test_something(boolean: bool) -> None:
10-
"""Test something here."""
11+
def test_something_hypothesis(boolean: bool) -> None:
12+
"""Test something here using Hypothesis."""
13+
assert Something.do_something(boolean) is True
14+
15+
16+
def _case_boolean() -> bool:
17+
fake = faker.Faker()
18+
return fake.pybool()
19+
20+
21+
@parametrize_with_cases("boolean", cases=_case_boolean)
22+
def test_something_cases(boolean: bool) -> None:
23+
"""Test something here using Cases and Faker."""
1124
assert Something.do_something(boolean) is True

0 commit comments

Comments
 (0)