pytest-qaseio


Namepytest-qaseio JSON
Version 2.1.2 PyPI version JSON
download
home_pagehttps://pypi.org/project/pytest-qaseio/
SummaryPytest plugin for Qase.io integration
upload_time2024-11-18 06:35:57
maintainerNone
docs_urlNone
authorSaritasa
requires_python<4.0,>=3.11
licenseMIT
keywords pytest qase qaseio selenium autotests
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-qaseio

[![Build Status](https://github.com/saritasa-nest/pytest-qaseio/workflows/checks/badge.svg?branch=main&event=push)](https://github.com/saritasa-nest/pytest-qaseio/actions?query=workflow%3Achecks)
[![Python Version](https://img.shields.io/pypi/pyversions/pytest-qaseio.svg)](https://pypi.org/project/pytest-qaseio/)

Another implementation of Pytest plugin for Qase.io integration

Our features:

* Extended error report for Selenium (screenshot, html and browser logs)
* Strict case ids validations
* Instead of case ids, it uses direct links to cases
* Custom file storage for attachments
* Provide URL of test run starter
* Most of configuration options use environment variables

Not supported currently:

* Adding results to existing test runs
* Test steps

## Installation

```bash
pip install pytest-qaseio
```

## Configuration

To work with plugin you have to provide the following environment variables:

* `QASE_PROJECT_CODE` - Code of your Qase.io project

* `QASE_TOKEN` - API token to interact with Qase.io runs via API

A few more configuration environment variables are also available:
`QASE_PLAN_ID`, `QASE_ENVIRONMENT_ID` and `QASE_URL_CUSTOM_FIELD_ID`.

Specifying plan allows to create run "from template".
New run will contain all cases from plan + cases that specified in tests

`QASE_URL_CUSTOM_FIELD_ID` and `RUN_SOURCE_URL`  variables allow to specify custom
field ID to store the [URL of the run source](#set-run-source-url)

## Usage

To connect your python test with `Qase.io` just use `qase` mark and specify test case url:

```python
import pytest

@pytest.mark.qase("https://app.qase.io/case/DEMO-1")
def test_demo():
    """Check qaseio plugin works as expected."""
```

Since this package is mostly used for selenium tests, it expects to get browser
name to use in Qase.io test run name and in attachments path. By default you can
 provide it using `--webdriver` flag. But you can also override
 `pytest_qase_browser_name` hook to implement some custom logic.
 Here's default implementation of hook:

 ```python
@pytest.hookimpl(trylast=True)
def pytest_qase_browser_name(config: pytest.Config) -> str:
    """Try to get browser name from `webdriver` pytest option."""
    return config.getoption("--webdriver")

 ```

To enable plugin use flag `--qase-enabled`.

```bash
pytest tests/ --qase-enabled --webdriver=chrome
```

## Work with Selenium

This plugin expects to be used with selenium and provides additional debug
info from browser. To make it possible, prepare fixture that provides webdriver
and use the following snippet to set `_webdriver` attribute for each test:

```python
@pytest.fixture(autouse=True)
def annotate_node_with_driver(self, request: SubRequest):
  """Add webdriver instance to test, that later will be used to generate debug info.

  This fixture detects whether a test or its parent is using a selenium webdriver, and marks
  the node with the webdriver instance.

  """
  for fixture_name in request.fixturenames:
    if fixture_name.endswith("webdriver") and isinstance(
      request.getfixturevalue(fixture_name), selenium_webdriver.Remote,
    ):
      request.node._webdriver = request.getfixturevalue(fixture_name)
```

## File storage

`pytest-qaseio` plugin provides additional debug information in comment for
failed tests. It prepares browser log, html and screenshot. To store this
files plugin uses file storage. By default plugin provides and uses `QaseFileStorage`
that uploads files to Qase.io S3 bucket via attachments API.
If you don't want to upload files, just set `--qase-file-storage=None` option.

You can also provide your custom file storage. To do this, follow the next steps:

1) Prepare object that implements `save_file_obj()` method according to `storage.FileProtocol`
2) Override `pytest_qase_file_storages` hook and add mapping to your storage
3) Use `--qase-file-storage` option to specify name of you storage

**Note**: Keep in mind that `None` choice is reserved for disabling storages.

Example:

```python

## storages.py

class S3FileStorage:

  def __init__(self, **credentials): ...

  def save_file_obj(self, content: bytes, filename: str, **kwargs) -> str:
    """Upload file to S3 and get it's url."""
    self.s3_client.put_object(
        Body=content,
        Bucket=self.bucket,
        Key=filename,
        **kwargs,
    )
    return f"{self.s3_client.meta.endpoint_url}/{self.bucket}/{filename}"

## conftest.py

@pytest.hookimpl(tryfirst=True)
def pytest_qase_file_storages() -> dict[str, qase_storages.FileStorage]:
    """Override file storages to use custom S3 bucket."""
    return {
        "s3": S3FSStorage(),
    }

## Run tests
$ pytest --qase-enabled --qase-file-storage=s3

```

You can also override `qase_file_storage` to set storage for part of tests
(or for all in global `conftests.py`):

```python
@pytest.fixture
def qase_file_storage() -> storage.FileProtocol:
  return S3FileStorage()
```

## Pytest options

Plugin provides two pytest options:

`--qase-enabled` - use turn on qase plugin and run your tests with Qase.io integration

`--qase-file-storage` - allows to choose storage to upload additional debug info for failed tests.
                        `None` and `qase` choices are available by default.

## Set run source url

Sometimes it might be useful to see the source that runs tests. If you need this,
you have to [create custom field](https://help.qase.io/en/articles/5563701-custom-fields)
for your Qase.io project.

Then you need to find `ID` of this field and set `QASE_URL_CUSTOM_FIELD_ID` environment variable.
To find custom field ID:

 1. open project -> `Test runs` -> `Start new test run`
 2. inspect custom field section with browser dev tools
 3. find label or text area of this custom field and you will see id in next format `cf-1-31`. The last number (`31`) is ID.

Finally, provide `RUN_SOURCE_URL` environment variable with URL to test run.

## License

[MIT](https://github.com/saritasa-nest/pytest-qaseio/blob/main/LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/pytest-qaseio/",
    "name": "pytest-qaseio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": "pytest, qase, qaseio, selenium, autotests",
    "author": "Saritasa",
    "author_email": "pypi@saritasa.com",
    "download_url": "https://files.pythonhosted.org/packages/98/4e/65b3fc6c1c3a8ac0122ed22838ba9d42ce5902d5c325277c22f14ea5478a/pytest_qaseio-2.1.2.tar.gz",
    "platform": null,
    "description": "# pytest-qaseio\n\n[![Build Status](https://github.com/saritasa-nest/pytest-qaseio/workflows/checks/badge.svg?branch=main&event=push)](https://github.com/saritasa-nest/pytest-qaseio/actions?query=workflow%3Achecks)\n[![Python Version](https://img.shields.io/pypi/pyversions/pytest-qaseio.svg)](https://pypi.org/project/pytest-qaseio/)\n\nAnother implementation of Pytest plugin for Qase.io integration\n\nOur features:\n\n* Extended error report for Selenium (screenshot, html and browser logs)\n* Strict case ids validations\n* Instead of case ids, it uses direct links to cases\n* Custom file storage for attachments\n* Provide URL of test run starter\n* Most of configuration options use environment variables\n\nNot supported currently:\n\n* Adding results to existing test runs\n* Test steps\n\n## Installation\n\n```bash\npip install pytest-qaseio\n```\n\n## Configuration\n\nTo work with plugin you have to provide the following environment variables:\n\n* `QASE_PROJECT_CODE` - Code of your Qase.io project\n\n* `QASE_TOKEN` - API token to interact with Qase.io runs via API\n\nA few more configuration environment variables are also available:\n`QASE_PLAN_ID`, `QASE_ENVIRONMENT_ID` and `QASE_URL_CUSTOM_FIELD_ID`.\n\nSpecifying plan allows to create run \"from template\".\nNew run will contain all cases from plan + cases that specified in tests\n\n`QASE_URL_CUSTOM_FIELD_ID` and `RUN_SOURCE_URL`  variables allow to specify custom\nfield ID to store the [URL of the run source](#set-run-source-url)\n\n## Usage\n\nTo connect your python test with `Qase.io` just use `qase` mark and specify test case url:\n\n```python\nimport pytest\n\n@pytest.mark.qase(\"https://app.qase.io/case/DEMO-1\")\ndef test_demo():\n    \"\"\"Check qaseio plugin works as expected.\"\"\"\n```\n\nSince this package is mostly used for selenium tests, it expects to get browser\nname to use in Qase.io test run name and in attachments path. By default you can\n provide it using `--webdriver` flag. But you can also override\n `pytest_qase_browser_name` hook to implement some custom logic.\n Here's default implementation of hook:\n\n ```python\n@pytest.hookimpl(trylast=True)\ndef pytest_qase_browser_name(config: pytest.Config) -> str:\n    \"\"\"Try to get browser name from `webdriver` pytest option.\"\"\"\n    return config.getoption(\"--webdriver\")\n\n ```\n\nTo enable plugin use flag `--qase-enabled`.\n\n```bash\npytest tests/ --qase-enabled --webdriver=chrome\n```\n\n## Work with Selenium\n\nThis plugin expects to be used with selenium and provides additional debug\ninfo from browser. To make it possible, prepare fixture that provides webdriver\nand use the following snippet to set `_webdriver` attribute for each test:\n\n```python\n@pytest.fixture(autouse=True)\ndef annotate_node_with_driver(self, request: SubRequest):\n  \"\"\"Add webdriver instance to test, that later will be used to generate debug info.\n\n  This fixture detects whether a test or its parent is using a selenium webdriver, and marks\n  the node with the webdriver instance.\n\n  \"\"\"\n  for fixture_name in request.fixturenames:\n    if fixture_name.endswith(\"webdriver\") and isinstance(\n      request.getfixturevalue(fixture_name), selenium_webdriver.Remote,\n    ):\n      request.node._webdriver = request.getfixturevalue(fixture_name)\n```\n\n## File storage\n\n`pytest-qaseio` plugin provides additional debug information in comment for\nfailed tests. It prepares browser log, html and screenshot. To store this\nfiles plugin uses file storage. By default plugin provides and uses `QaseFileStorage`\nthat uploads files to Qase.io S3 bucket via attachments API.\nIf you don't want to upload files, just set `--qase-file-storage=None` option.\n\nYou can also provide your custom file storage. To do this, follow the next steps:\n\n1) Prepare object that implements `save_file_obj()` method according to `storage.FileProtocol`\n2) Override `pytest_qase_file_storages` hook and add mapping to your storage\n3) Use `--qase-file-storage` option to specify name of you storage\n\n**Note**: Keep in mind that `None` choice is reserved for disabling storages.\n\nExample:\n\n```python\n\n## storages.py\n\nclass S3FileStorage:\n\n  def __init__(self, **credentials): ...\n\n  def save_file_obj(self, content: bytes, filename: str, **kwargs) -> str:\n    \"\"\"Upload file to S3 and get it's url.\"\"\"\n    self.s3_client.put_object(\n        Body=content,\n        Bucket=self.bucket,\n        Key=filename,\n        **kwargs,\n    )\n    return f\"{self.s3_client.meta.endpoint_url}/{self.bucket}/{filename}\"\n\n## conftest.py\n\n@pytest.hookimpl(tryfirst=True)\ndef pytest_qase_file_storages() -> dict[str, qase_storages.FileStorage]:\n    \"\"\"Override file storages to use custom S3 bucket.\"\"\"\n    return {\n        \"s3\": S3FSStorage(),\n    }\n\n## Run tests\n$ pytest --qase-enabled --qase-file-storage=s3\n\n```\n\nYou can also override `qase_file_storage` to set storage for part of tests\n(or for all in global `conftests.py`):\n\n```python\n@pytest.fixture\ndef qase_file_storage() -> storage.FileProtocol:\n  return S3FileStorage()\n```\n\n## Pytest options\n\nPlugin provides two pytest options:\n\n`--qase-enabled` - use turn on qase plugin and run your tests with Qase.io integration\n\n`--qase-file-storage` - allows to choose storage to upload additional debug info for failed tests.\n                        `None` and `qase` choices are available by default.\n\n## Set run source url\n\nSometimes it might be useful to see the source that runs tests. If you need this,\nyou have to [create custom field](https://help.qase.io/en/articles/5563701-custom-fields)\nfor your Qase.io project.\n\nThen you need to find `ID` of this field and set `QASE_URL_CUSTOM_FIELD_ID` environment variable.\nTo find custom field ID:\n\n 1. open project -> `Test runs` -> `Start new test run`\n 2. inspect custom field section with browser dev tools\n 3. find label or text area of this custom field and you will see id in next format `cf-1-31`. The last number (`31`) is ID.\n\nFinally, provide `RUN_SOURCE_URL` environment variable with URL to test run.\n\n## License\n\n[MIT](https://github.com/saritasa-nest/pytest-qaseio/blob/main/LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Pytest plugin for Qase.io integration",
    "version": "2.1.2",
    "project_urls": {
        "Homepage": "https://pypi.org/project/pytest-qaseio/",
        "Repository": "https://github.com/saritasa-nest/pytest-qaseio"
    },
    "split_keywords": [
        "pytest",
        " qase",
        " qaseio",
        " selenium",
        " autotests"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d67a3f778e6b9f5030dee9ae90d8e3117efe26fa571db46ed632c60e34f481b",
                "md5": "b529d86b75f97bd774dd402fdf23a561",
                "sha256": "5dbe9233032f6dc0a55e693cb694624640601811803029b1e94f0bce7858dbee"
            },
            "downloads": -1,
            "filename": "pytest_qaseio-2.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b529d86b75f97bd774dd402fdf23a561",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 15091,
            "upload_time": "2024-11-18T06:35:55",
            "upload_time_iso_8601": "2024-11-18T06:35:55.826000Z",
            "url": "https://files.pythonhosted.org/packages/4d/67/a3f778e6b9f5030dee9ae90d8e3117efe26fa571db46ed632c60e34f481b/pytest_qaseio-2.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "984e65b3fc6c1c3a8ac0122ed22838ba9d42ce5902d5c325277c22f14ea5478a",
                "md5": "acca30503a92a5e72a7e8e2e7c475348",
                "sha256": "855a29e8cbf3de4f526716605e5b61ce33d2c9bb00680f190b9b914f9ecb969e"
            },
            "downloads": -1,
            "filename": "pytest_qaseio-2.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "acca30503a92a5e72a7e8e2e7c475348",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 15400,
            "upload_time": "2024-11-18T06:35:57",
            "upload_time_iso_8601": "2024-11-18T06:35:57.762465Z",
            "url": "https://files.pythonhosted.org/packages/98/4e/65b3fc6c1c3a8ac0122ed22838ba9d42ce5902d5c325277c22f14ea5478a/pytest_qaseio-2.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-18 06:35:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "saritasa-nest",
    "github_project": "pytest-qaseio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-qaseio"
}
        
Elapsed time: 0.44430s