# vedro-matrix
[](https://pypi.org/project/vedro-matrix/)
[](https://github.com/mickeystreicher/vedro-matrix/blob/main/LICENSE)
`vedro-matrix` is a Python package that extends the [Vedro](https://vedro.io/) framework, enabling parameterized testing with matrix combinations. It simplifies the process of creating and managing multiple test scenarios, especially when dealing with combinations of different test parameters like browsers, screen resolutions, user types, etc.
## Installation
Install [vedro-matrix](https://pypi.org/project/vedro-matrix/) using pip:
```sh
$ pip install vedro-matrix
```
## Usage
To use `vedro-matrix`, import the `params_matrix` decorator from the package and apply it to your test scenarios in a `vedro` test suite.
### Example
Here is an example of how to use `vedro-matrix` to test a web page's rendering on different browsers and resolutions:
```python
import vedro
from vedro_matrix import params_matrix
class Scenario(vedro.Scenario):
subject = "Open /about page ({browser}, {resolution})"
@params_matrix(
["chrome", "firefox"],
["1024x720", "1920x1080"],
)
def __init__(self, browser, resolution):
self.browser = browser
self.resolution = resolution
def when_user_opens_page(self):
self.page = open_about_page(self.browser, self.resolution)
def then_it_should_show_main_content(self):
assert self.page.main_content.is_visible()
```
This script will generate and run 4 separate test scenarios:
1. Open /about page (chrome, 1024x720)
2. Open /about page (chrome, 1920x1080)
3. Open /about page (firefox, 1024x720)
4. Open /about page (firefox, 1920x1080)
### Running Tests
Run the scenarios using the `vedro` command:
```sh
$ vedro run
```
You should see an output similar to the following, indicating that all scenarios have passed:
```sh
Scenarios
*
✔ Open /about page (chrome, 1024x720)
✔ Open /about page (chrome, 1920x1080)
✔ Open /about page (firefox, 1024x720)
✔ Open /about page (firefox, 1920x1080)
# --seed 79b84f2d-e98c-47bf-b057-acdf597c4143
# 4 scenarios, 4 passed, 0 failed, 0 skipped (1.51s)
```
### Additional Usage Examples
In addition to the standard matrix setup with fixed parameters, `vedro-matrix` offers flexible options to generate test cases using various types of iterables, like lists or enums, which simplifies the process of defining complex combinations of test inputs.
**1. Simple Numeric Parameters**
You can use `vedro-matrix` to test different inputs, such as numeric IDs or other sequences. Here's an example where `post_id` varies:
```python
import vedro
from vedro_matrix import params_matrix
class Scenario(vedro.Scenario):
@params_matrix([1, 2, 3])
def __init__(self, post_id):
self.post_id = post_id
```
This will generate and run 3 test cases with the following values for `post_id`:
1. Scenario with `post_id = 1`
2. Scenario with `post_id = 2`
3. Scenario with `post_id = 3`
**2. Using Enums for Parameters**
In more structured setups, you can use enums to pass values to your test scenarios. This is particularly useful when the test parameters represent distinct options, such as browser types or user roles. Here's how to achieve that:
```python
import vedro
from vedro_matrix import params_matrix
from enum import StrEnum
class Browser(StrEnum):
CHROME = "chrome"
FIREFOX = "firefox"
class Scenario(vedro.Scenario):
@params_matrix(Browser)
def __init__(self, browser):
self.browser = browser
```
In this case, `vedro-matrix` will generate two scenarios:
1. Scenario with `browser = "chrome"`
2. Scenario with `browser = "firefox"`
This approach improves code readability and maintainability, especially when managing larger test matrices with more complex inputs.
Raw data
{
"_id": null,
"home_page": "https://github.com/mickeystreicher/vedro-matrix",
"name": "vedro-matrix",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Mickey Streicher",
"author_email": "mickeystreicher@fastmail.us",
"download_url": "https://files.pythonhosted.org/packages/f1/61/611e727ec820728e64f28bd191057da62eeb822d1a59104dcfcbbc642ca1/vedro_matrix-1.0.0.tar.gz",
"platform": null,
"description": "# vedro-matrix\n\n[](https://pypi.org/project/vedro-matrix/)\n[](https://github.com/mickeystreicher/vedro-matrix/blob/main/LICENSE)\n\n`vedro-matrix` is a Python package that extends the [Vedro](https://vedro.io/) framework, enabling parameterized testing with matrix combinations. It simplifies the process of creating and managing multiple test scenarios, especially when dealing with combinations of different test parameters like browsers, screen resolutions, user types, etc.\n\n## Installation\n\nInstall [vedro-matrix](https://pypi.org/project/vedro-matrix/) using pip:\n\n```sh\n$ pip install vedro-matrix\n```\n\n## Usage\n\nTo use `vedro-matrix`, import the `params_matrix` decorator from the package and apply it to your test scenarios in a `vedro` test suite.\n\n### Example\n\nHere is an example of how to use `vedro-matrix` to test a web page's rendering on different browsers and resolutions:\n\n```python\nimport vedro\nfrom vedro_matrix import params_matrix\n\nclass Scenario(vedro.Scenario):\n subject = \"Open /about page ({browser}, {resolution})\"\n\n @params_matrix(\n [\"chrome\", \"firefox\"],\n [\"1024x720\", \"1920x1080\"],\n )\n def __init__(self, browser, resolution):\n self.browser = browser\n self.resolution = resolution\n\n def when_user_opens_page(self):\n self.page = open_about_page(self.browser, self.resolution)\n\n def then_it_should_show_main_content(self):\n assert self.page.main_content.is_visible()\n```\n\nThis script will generate and run 4 separate test scenarios:\n\n1. Open /about page (chrome, 1024x720)\n2. Open /about page (chrome, 1920x1080)\n3. Open /about page (firefox, 1024x720)\n4. Open /about page (firefox, 1920x1080)\n\n### Running Tests\n\nRun the scenarios using the `vedro` command:\n\n```sh\n$ vedro run\n```\n\nYou should see an output similar to the following, indicating that all scenarios have passed:\n\n```sh\nScenarios\n*\n \u2714 Open /about page (chrome, 1024x720)\n \u2714 Open /about page (chrome, 1920x1080)\n \u2714 Open /about page (firefox, 1024x720)\n \u2714 Open /about page (firefox, 1920x1080)\n\n# --seed 79b84f2d-e98c-47bf-b057-acdf597c4143\n# 4 scenarios, 4 passed, 0 failed, 0 skipped (1.51s)\n```\n\n### Additional Usage Examples\n\nIn addition to the standard matrix setup with fixed parameters, `vedro-matrix` offers flexible options to generate test cases using various types of iterables, like lists or enums, which simplifies the process of defining complex combinations of test inputs.\n\n**1. Simple Numeric Parameters**\n\nYou can use `vedro-matrix` to test different inputs, such as numeric IDs or other sequences. Here's an example where `post_id` varies:\n\n```python\nimport vedro\nfrom vedro_matrix import params_matrix\n\nclass Scenario(vedro.Scenario):\n @params_matrix([1, 2, 3])\n def __init__(self, post_id):\n self.post_id = post_id\n```\n\nThis will generate and run 3 test cases with the following values for `post_id`:\n\n1. Scenario with `post_id = 1`\n2. Scenario with `post_id = 2`\n3. Scenario with `post_id = 3`\n\n**2. Using Enums for Parameters**\n\nIn more structured setups, you can use enums to pass values to your test scenarios. This is particularly useful when the test parameters represent distinct options, such as browser types or user roles. Here's how to achieve that:\n\n```python\nimport vedro\nfrom vedro_matrix import params_matrix\nfrom enum import StrEnum\n\nclass Browser(StrEnum):\n CHROME = \"chrome\"\n FIREFOX = \"firefox\"\n\n\nclass Scenario(vedro.Scenario):\n @params_matrix(Browser)\n def __init__(self, browser):\n self.browser = browser\n```\n\nIn this case, `vedro-matrix` will generate two scenarios:\n\n1. Scenario with `browser = \"chrome\"`\n2. Scenario with `browser = \"firefox\"`\n\nThis approach improves code readability and maintainability, especially when managing larger test matrices with more complex inputs.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Simplify parameterized testing with matrix combinations of diverse test parameters",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/mickeystreicher/vedro-matrix",
"Repository": "https://github.com/mickeystreicher/vedro-matrix"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "74c7695e38180b685ae5823a4a8eb4c5d815fb4480683326e56b87c2ef81bdda",
"md5": "6fc9c22d9edb3f4db44b66e78dce4a1e",
"sha256": "d4d695cd597453e5fa45328c24f59f96174462abe1b4a5be35a536c960cf8edb"
},
"downloads": -1,
"filename": "vedro_matrix-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6fc9c22d9edb3f4db44b66e78dce4a1e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7661,
"upload_time": "2024-10-19T07:45:52",
"upload_time_iso_8601": "2024-10-19T07:45:52.160503Z",
"url": "https://files.pythonhosted.org/packages/74/c7/695e38180b685ae5823a4a8eb4c5d815fb4480683326e56b87c2ef81bdda/vedro_matrix-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f161611e727ec820728e64f28bd191057da62eeb822d1a59104dcfcbbc642ca1",
"md5": "f621ca77fcc4530bda124b156a9dc096",
"sha256": "893db764a691729a02d32cfdf095c41c671a48deaa493496fd822c2f37bb3a35"
},
"downloads": -1,
"filename": "vedro_matrix-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "f621ca77fcc4530bda124b156a9dc096",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6858,
"upload_time": "2024-10-19T07:45:53",
"upload_time_iso_8601": "2024-10-19T07:45:53.640323Z",
"url": "https://files.pythonhosted.org/packages/f1/61/611e727ec820728e64f28bd191057da62eeb822d1a59104dcfcbbc642ca1/vedro_matrix-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-19 07:45:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mickeystreicher",
"github_project": "vedro-matrix",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "vedro-matrix"
}