# pytest-case
![workflow success](https://github.com/eitanwass/pytest-case/actions/workflows/pytest-case-ci.yml/badge.svg) [![codecov](https://codecov.io/github/eitanwass/pytest-case/graph/badge.svg?token=07NGAILDL2)](https://codecov.io/github/eitanwass/pytest-case)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-case) [![PyPI - Version](https://img.shields.io/pypi/v/pytest-case)](https://pypi.org/project/pytest-case)
# Usage examples:
```python
import pytest
from typing import Tuple, Generator
from pytest_case import case
def add_test_cases() -> Generator[Tuple[int, int, int]]:
yield (
n
for n in [
(3, 3, 6),
(3, 4, 7),
(-1, 6, 5),
]
)
@case("regular args", 4, 2, 2)
@case(
"params as kwargs",
a=2,
b=2,
expected=1,
)
@case('with expected fail', 1, 0, -1, mark=pytest.mark.xfail)
@case(add_test_cases())
def test__divide(a: int, b: int, expected: int) -> None:
assert expected == a / b
```
# Features
## Default Arguments Values
```python
@case("Check for Failure", val="Failure")
@case("Check for success", val="Success", sanity="Success")
def test__with_default(val: str, sanity: str = "Failure") -> None:
assert sanity == val
```
## Generator Case
```python
from itertools import product
from pytest_case import case
@case(product(
("Chrome", "Firefox", "Safari"),
("Windows", "macOS", "Linux")
))
def test__browser_os_compatibility(browser: str, operating_system: str) -> None:
# Will generate cases:
# ("Chrome", "Windows"), ("Chrome", "macOS"), ("Chrome", "Linux"), ("Firefox", "Windows"), ...
pass
```
## Using Fixtures
- Using pytest built-in `request` fixture.
```python
def test__with_request_fixture(request: Any) -> None:
fixture_value = request.getfixturevalue("fixture_name")
...
```
- Using [pytest-lazy-fixtures](https://github.com/dev-petrov/pytest-lazy-fixtures)
```python
from pytest_case import case
from pytest_lazy_fixtures import lf
@case("Lazy Fixture Case", lf("fixture_name"))
def test__with_lf_cases(fixture_val: Any) -> None
...
```
# Project Roadmap:
These are the the predicted checkpoints for this project:
- [x] **Test Arguments Default Values**
That would be cool!
- [x] **Test Marks**
Marks that are currently supported by pytest, such as: xfail, skip, ...
- [x] **Tests Cases Generators**
Provide a generator function to the `case` to automatically generate cases.
- [x] **Use Fixtures**
Use fixtures in cases and tests
- [ ] **Tests Samples Generation**
Generate parameters to catch edge-cases, based on restrictions or datasets.
Raw data
{
"_id": null,
"home_page": "https://github.com/eitanwass/pytest-case",
"name": "pytest-case",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "pytest, parametrize, case, test",
"author": "Ethan Wass",
"author_email": "eitanwass@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c0/70/05e97274ffe052b886a2accf77ad00b01628b27fd34cebb7514655e8268f/pytest_case-1.0.0.tar.gz",
"platform": null,
"description": "# pytest-case\n\n![workflow success](https://github.com/eitanwass/pytest-case/actions/workflows/pytest-case-ci.yml/badge.svg) [![codecov](https://codecov.io/github/eitanwass/pytest-case/graph/badge.svg?token=07NGAILDL2)](https://codecov.io/github/eitanwass/pytest-case) \n\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-case) [![PyPI - Version](https://img.shields.io/pypi/v/pytest-case)](https://pypi.org/project/pytest-case)\n\n\n# Usage examples:\n\n```python\nimport pytest\nfrom typing import Tuple, Generator\nfrom pytest_case import case\n\n\ndef add_test_cases() -> Generator[Tuple[int, int, int]]:\n yield (\n n\n for n in [\n (3, 3, 6),\n (3, 4, 7),\n (-1, 6, 5),\n ]\n )\n\n\n@case(\"regular args\", 4, 2, 2)\n@case(\n \"params as kwargs\",\n a=2,\n b=2,\n expected=1,\n)\n@case('with expected fail', 1, 0, -1, mark=pytest.mark.xfail)\n@case(add_test_cases())\ndef test__divide(a: int, b: int, expected: int) -> None:\n assert expected == a / b\n```\n\n# Features\n\n## Default Arguments Values\n```python\n@case(\"Check for Failure\", val=\"Failure\")\n@case(\"Check for success\", val=\"Success\", sanity=\"Success\")\ndef test__with_default(val: str, sanity: str = \"Failure\") -> None:\n assert sanity == val\n```\n\n## Generator Case\n```python\nfrom itertools import product\nfrom pytest_case import case\n\n@case(product(\n (\"Chrome\", \"Firefox\", \"Safari\"), \n (\"Windows\", \"macOS\", \"Linux\")\n))\ndef test__browser_os_compatibility(browser: str, operating_system: str) -> None:\n # Will generate cases:\n # (\"Chrome\", \"Windows\"), (\"Chrome\", \"macOS\"), (\"Chrome\", \"Linux\"), (\"Firefox\", \"Windows\"), ...\n pass\n```\n\n## Using Fixtures\n- Using pytest built-in `request` fixture.\n ```python\n def test__with_request_fixture(request: Any) -> None:\n fixture_value = request.getfixturevalue(\"fixture_name\")\n ...\n ```\n- Using [pytest-lazy-fixtures](https://github.com/dev-petrov/pytest-lazy-fixtures)\n ```python\n from pytest_case import case\n from pytest_lazy_fixtures import lf\n\n\n @case(\"Lazy Fixture Case\", lf(\"fixture_name\"))\n def test__with_lf_cases(fixture_val: Any) -> None\n ...\n ```\n\n# Project Roadmap:\nThese are the the predicted checkpoints for this project:\n\n- [x] **Test Arguments Default Values**\n That would be cool!\n- [x] **Test Marks**\n Marks that are currently supported by pytest, such as: xfail, skip, ...\n- [x] **Tests Cases Generators**\n Provide a generator function to the `case` to automatically generate cases.\n- [x] **Use Fixtures**\n Use fixtures in cases and tests\n- [ ] **Tests Samples Generation**\n Generate parameters to catch edge-cases, based on restrictions or datasets.\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A clean, modern, wrapper for pytest.mark.parametrize",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/eitanwass/pytest-case",
"Repository": "https://github.com/eitanwass/pytest-case"
},
"split_keywords": [
"pytest",
" parametrize",
" case",
" test"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f0a2ec8a13283d23c32cef21eae8b494fadf436dce131df6166bbdd9087a86ee",
"md5": "741361bd3b716c4e72f570d98169167c",
"sha256": "2c0f25e6920f1a2a1cdc0cdb1066265666b18f370dc5c5a96013cd3692bae9cd"
},
"downloads": -1,
"filename": "pytest_case-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "741361bd3b716c4e72f570d98169167c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 10292,
"upload_time": "2024-11-25T20:05:49",
"upload_time_iso_8601": "2024-11-25T20:05:49.743989Z",
"url": "https://files.pythonhosted.org/packages/f0/a2/ec8a13283d23c32cef21eae8b494fadf436dce131df6166bbdd9087a86ee/pytest_case-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c07005e97274ffe052b886a2accf77ad00b01628b27fd34cebb7514655e8268f",
"md5": "1dc706ee5f897fc23f7a1f4dc0bc1279",
"sha256": "12dfb557ad760ea517c429a20743d95d536a008a2a1c5e663e5dfcc25109bd8b"
},
"downloads": -1,
"filename": "pytest_case-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "1dc706ee5f897fc23f7a1f4dc0bc1279",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 8499,
"upload_time": "2024-11-25T20:05:51",
"upload_time_iso_8601": "2024-11-25T20:05:51.704498Z",
"url": "https://files.pythonhosted.org/packages/c0/70/05e97274ffe052b886a2accf77ad00b01628b27fd34cebb7514655e8268f/pytest_case-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-25 20:05:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "eitanwass",
"github_project": "pytest-case",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pytest-case"
}