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

feat(test): add the pytest-cases package and a simple example of how to use it #873

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ hooks = [
]
# Note that the `custom_exit_code` and `env` plugins may currently be unmaintained.
test = [
"faker ==35.0.0",
"hypothesis >=6.21.0,<6.122.8",
"pytest >=7.2.0,<9.0.0",
"pytest-cases ==3.8.6",
"pytest-custom_exit_code ==0.3.0",
"pytest-cov ==6.0.0",
"pytest-doctestplus ==1.3.0",
Expand Down
17 changes: 15 additions & 2 deletions tests/test_something.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
"""Test the Something module. Add more tests here, as needed."""

import faker
from hypothesis import given, strategies
from pytest_cases import parametrize_with_cases

from package.something import Something


@given(strategies.booleans())
def test_something(boolean: bool) -> None:
"""Test something here."""
def test_something_hypothesis(boolean: bool) -> None:
"""Test something here using Hypothesis."""
assert Something.do_something(boolean) is True


def _case_boolean() -> bool:
fake = faker.Faker()
return fake.pybool()


@parametrize_with_cases("boolean", cases=_case_boolean)
def test_something_cases(boolean: bool) -> None:
"""Test something here using Cases and Faker."""
assert Something.do_something(boolean) is True
Loading