# [Qase TestOps](https://qase.io) Pytest Reporter
[![License](https://lxgaming.github.io/badges/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
## Installation
To install the latest version, run:
```sh
pip install pre qase-pytest
```
## Upgrade from 4.x to 5.x and to 6.x
The new version 6.x of the Pytest reporter has breaking changes.
To migrate from versions 4.x or 5.x, follow the [upgrade guide](docs/UPGRADE.md).
## Configuration
Qase Pytest Reporter is configured in multiple ways:
- using a config file `qase.config.json`
- using environment variables
- using command line options
Environment variables override the values given in the config file,
and command line options override both other values.
Configuration options are described in the
[configuration reference](docs/CONFIGURATION.md).
### Example: qase.config.json
```json
{
"mode": "testops",
"fallback": "report",
"testops": {
"project": "YOUR_PROJECT_CODE",
"api": {
"token": "YOUR_API_TOKEN",
"host": "qase.io"
},
"run": {
"title": "Test run title"
},
"batch": {
"size": 100
}
},
"report": {
"driver": "local",
"connection": {
"local": {
"path": "./build/qase-report",
"format": "json"
}
}
},
"framework": {
"pytest": {
"capture": {
"logs": true,
"http": true
}
}
},
"environment": "local"
}
```
## Usage
### Link tests with test cases in Qase TestOps
To link the automated tests with the test cases in Qase TestOps, use the `@qase.id()` decorator.
Other test data, such as case title, system and custom fields,
can be added with `@qase.title()` and `@qase.fields()`:
```python
from qase.pytest import qase
@qase.id(13)
@qase.title("My first test")
@qase.fields(
("severity", "critical"),
("priority", "high"),
("layer", "unit"),
("description", "Try to login to Qase TestOps using login and password"),
("preconditions", "*Precondition 1*. Markdown is supported."),
)
def test_example_1():
pass
```
Each unique number can only be assigned once to the class or function being used.
### Ignore a particular test
To exclude a particular test from the report, use the `@qase.ignore` decorator:
```python
from qase.pytest import qase
@qase.ignore
def test_example_1():
pass
```
### Possible test result statuses
- PASSED - when test passed
- FAILED - when test failed with `AssertionError`
- BLOCKED - when test failed with any other exception
- SKIPPED - when test has been skipped
### Capture network logs
To capture the network logs, enable the `http` option in the `framework.capture` section
of the configuration file.
The Qase Pytest reporter will capture all HTTP requests and responses
and save them as a test steps automatically.
### Add attachments to test results
To upload screenshots, logs, and other information to Qase.io,
use `qase.attach()`.
It works both with files in the filesystem and with data available in the code.
There is no limit on the amount of attachments from a single test.
```python
import pytest
from qase.pytest import qase
@qase.title("File attachments")
def test_example_1():
# attach files from the filesystem:
qase.attach("/path/to/file", "/path/to/file/2")
# to add multiple attachments, pass them in tuples:
qase.attach(
("/path/to/file/1", "application/json"),
("/path/to/file/3", "application/xml"),
)
@pytest.fixture(scope="session")
def driver():
driver = webdriver.Chrome()
yield driver
logs = "\n".join(str(row) for row in driver.get_log('browser')).encode('utf-8')
# attach logs from a code variable as a text file:
qase.attach((logs, "text/plain", "browser.log"))
driver.quit()
@qase.id(12)
def test_example_2(driver):
# attach the output of driver.get_screenshot_as_png() as a png image
qase.attach((driver.get_screenshot_as_png(), "image/png", "result.png"))
```
### Linking code with steps
To mark a test step, either annotate a function with `@qase.step()`,
or use the `with qase.step()` context:
```python
from qase.pytest import qase
@qase.step("First step") # test step name
def some_step():
sleep(5)
@qase.step("Second step") # test step name
def another_step():
sleep(3)
# ...
def test_example():
some_step()
another_step()
# test step hash
with qase.step("Third step"):
sleep(1)
```
### Creating new testrun according to current pytest run
By default, qase-pytest will create a new test run in Qase TestOps
and report results to this test run.
To provide a custom name for this run, add
the option `--qase-testops-run-title`.
```bash
pytest \
--qase-mode=testops \
--qase-testops-api-token=<your api token here> \
--qase-testops-project=PRJCODE \ # project, where your testrun would be created
--qase-testops-run-title=My\ First\ Automated\ Run
```
### Sending tests to existing testrun
Test results can be reported to an existing test run in Qase using its ID.
This is useful when a test run combines tests from multiple sources:
* manual and automated
* autotests from different frameworks
* tests running in multiple shards on different machines
For example, if the test run has ID=3, the following command will
run tests and report results to this test run:
```bash
pytest \
--qase-mode=testops \
--qase-testops-api-token=<your api token here> \
--qase-testops-project=PRJCODE \ # project, where the test run is created
--qase-testops-run-id=3 # testrun id
```
### Creating test run based on test plan (selective launch)
Create a new testrun base on a testplan. Testrun in Qase TestOps will contain only those
test results. `qase-pytest` supports selective execution.
```bash
pytest \
--qase-mode=testops \
--qase-testops-api-token=<your api token here> \
--qase-testops-project=PRJCODE \ # project, where your testrun exists in
--qase-testops-plan-id=3 # testplan id
```
Raw data
{
"_id": null,
"home_page": null,
"name": "qase-pytest",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "qase, pytest, plugin, testops, report, qase reporting, test observability",
"author": null,
"author_email": "Qase Team <support@qase.io>",
"download_url": "https://files.pythonhosted.org/packages/06/e8/300f944d1b5c82bc809de325c63f2be0bb04555c92151750e8313e377092/qase_pytest-6.0.1.tar.gz",
"platform": null,
"description": "# [Qase TestOps](https://qase.io) Pytest Reporter\n\n[![License](https://lxgaming.github.io/badges/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\n## Installation\n\nTo install the latest version, run:\n\n```sh\npip install pre qase-pytest\n```\n\n## Upgrade from 4.x to 5.x and to 6.x\n\nThe new version 6.x of the Pytest reporter has breaking changes.\nTo migrate from versions 4.x or 5.x, follow the [upgrade guide](docs/UPGRADE.md).\n\n## Configuration\n\nQase Pytest Reporter is configured in multiple ways:\n\n- using a config file `qase.config.json`\n- using environment variables\n- using command line options\n\nEnvironment variables override the values given in the config file, \nand command line options override both other values.\n\nConfiguration options are described in the\n[configuration reference](docs/CONFIGURATION.md).\n\n\n### Example: qase.config.json\n\n```json\n{\n \"mode\": \"testops\", \n \"fallback\": \"report\",\n \"testops\": {\n \"project\": \"YOUR_PROJECT_CODE\",\n \"api\": {\n \"token\": \"YOUR_API_TOKEN\",\n \"host\": \"qase.io\"\n },\n \"run\": {\n \"title\": \"Test run title\"\n },\n \"batch\": {\n \"size\": 100\n }\n },\n \"report\": {\n \"driver\": \"local\",\n \"connection\": {\n \"local\": {\n \"path\": \"./build/qase-report\",\n \"format\": \"json\" \n }\n }\n },\n \"framework\": {\n \"pytest\": {\n \"capture\": {\n \"logs\": true,\n \"http\": true\n }\n }\n },\n \"environment\": \"local\"\n}\n```\n\n## Usage\n\n### Link tests with test cases in Qase TestOps\n\nTo link the automated tests with the test cases in Qase TestOps, use the `@qase.id()` decorator.\nOther test data, such as case title, system and custom fields,\ncan be added with `@qase.title()` and `@qase.fields()`:\n\n```python\nfrom qase.pytest import qase\n\n@qase.id(13)\n@qase.title(\"My first test\")\n@qase.fields(\n (\"severity\", \"critical\"),\n (\"priority\", \"high\"),\n (\"layer\", \"unit\"),\n (\"description\", \"Try to login to Qase TestOps using login and password\"),\n (\"preconditions\", \"*Precondition 1*. Markdown is supported.\"),\n)\ndef test_example_1():\n pass\n```\n\nEach unique number can only be assigned once to the class or function being used.\n\n### Ignore a particular test\n\nTo exclude a particular test from the report, use the `@qase.ignore` decorator:\n\n```python\nfrom qase.pytest import qase\n\n@qase.ignore\ndef test_example_1():\n pass\n```\n\n### Possible test result statuses\n\n- PASSED - when test passed\n- FAILED - when test failed with `AssertionError`\n- BLOCKED - when test failed with any other exception\n- SKIPPED - when test has been skipped\n\n### Capture network logs\n\nTo capture the network logs, enable the `http` option in the `framework.capture` section\nof the configuration file.\n\nThe Qase Pytest reporter will capture all HTTP requests and responses\nand save them as a test steps automatically.\n\n### Add attachments to test results\n\nTo upload screenshots, logs, and other information to Qase.io,\nuse `qase.attach()`.\nIt works both with files in the filesystem and with data available in the code.\nThere is no limit on the amount of attachments from a single test.\n\n```python\nimport pytest\nfrom qase.pytest import qase\n\n@qase.title(\"File attachments\")\ndef test_example_1():\n # attach files from the filesystem:\n qase.attach(\"/path/to/file\", \"/path/to/file/2\")\n # to add multiple attachments, pass them in tuples:\n qase.attach(\n (\"/path/to/file/1\", \"application/json\"),\n (\"/path/to/file/3\", \"application/xml\"),\n )\n\n@pytest.fixture(scope=\"session\")\ndef driver():\n driver = webdriver.Chrome()\n yield driver\n logs = \"\\n\".join(str(row) for row in driver.get_log('browser')).encode('utf-8')\n # attach logs from a code variable as a text file:\n qase.attach((logs, \"text/plain\", \"browser.log\"))\n driver.quit()\n\n@qase.id(12)\ndef test_example_2(driver):\n # attach the output of driver.get_screenshot_as_png() as a png image\n qase.attach((driver.get_screenshot_as_png(), \"image/png\", \"result.png\"))\n```\n\n### Linking code with steps\n\nTo mark a test step, either annotate a function with `@qase.step()`,\nor use the `with qase.step()` context:\n\n```python\nfrom qase.pytest import qase\n\n@qase.step(\"First step\") # test step name\ndef some_step():\n sleep(5)\n\n@qase.step(\"Second step\") # test step name\ndef another_step():\n sleep(3)\n\n# ...\n\ndef test_example():\n some_step()\n another_step()\n # test step hash\n with qase.step(\"Third step\"):\n sleep(1)\n```\n\n### Creating new testrun according to current pytest run\n\nBy default, qase-pytest will create a new test run in Qase TestOps\nand report results to this test run.\nTo provide a custom name for this run, add\nthe option `--qase-testops-run-title`.\n\n```bash\npytest \\\n --qase-mode=testops \\\n --qase-testops-api-token=<your api token here> \\\n --qase-testops-project=PRJCODE \\ # project, where your testrun would be created\n --qase-testops-run-title=My\\ First\\ Automated\\ Run\n```\n\n### Sending tests to existing testrun\n\nTest results can be reported to an existing test run in Qase using its ID.\nThis is useful when a test run combines tests from multiple sources:\n\n* manual and automated\n* autotests from different frameworks\n* tests running in multiple shards on different machines\n\nFor example, if the test run has ID=3, the following command will\nrun tests and report results to this test run:\n\n```bash\npytest \\\n --qase-mode=testops \\\n --qase-testops-api-token=<your api token here> \\\n --qase-testops-project=PRJCODE \\ # project, where the test run is created\n --qase-testops-run-id=3 # testrun id\n```\n\n### Creating test run based on test plan (selective launch)\n\nCreate a new testrun base on a testplan. Testrun in Qase TestOps will contain only those\ntest results. `qase-pytest` supports selective execution.\n\n```bash\npytest \\\n --qase-mode=testops \\\n --qase-testops-api-token=<your api token here> \\\n --qase-testops-project=PRJCODE \\ # project, where your testrun exists in\n --qase-testops-plan-id=3 # testplan id\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Qase Pytest Plugin for Qase TestOps and Qase Report",
"version": "6.0.1",
"project_urls": {
"Documentation": "https://developers.qase.io",
"Homepage": "https://qase.io",
"Repository": "https://github.com/qase-tms/qase-python/tree/master/qase-pytest"
},
"split_keywords": [
"qase",
" pytest",
" plugin",
" testops",
" report",
" qase reporting",
" test observability"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2f36df47ccb385297b77f149a5ba9d1120d03a0132aff225ea9b58b944be1885",
"md5": "b2df4698cbc0363840404a956a6fa4f4",
"sha256": "ae8f8a1e8ee61bfd0e8a4c8f4e285b7a53fcab4d58c946353c978ac1d55c4222"
},
"downloads": -1,
"filename": "qase_pytest-6.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b2df4698cbc0363840404a956a6fa4f4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 15445,
"upload_time": "2024-06-04T08:43:53",
"upload_time_iso_8601": "2024-06-04T08:43:53.347216Z",
"url": "https://files.pythonhosted.org/packages/2f/36/df47ccb385297b77f149a5ba9d1120d03a0132aff225ea9b58b944be1885/qase_pytest-6.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "06e8300f944d1b5c82bc809de325c63f2be0bb04555c92151750e8313e377092",
"md5": "c4b907b6629aae670e26a81872135ec0",
"sha256": "1150ecd2fd318c774ec3b32dfd635d071d46fc8f77da5ffe7c15aacb1132769d"
},
"downloads": -1,
"filename": "qase_pytest-6.0.1.tar.gz",
"has_sig": false,
"md5_digest": "c4b907b6629aae670e26a81872135ec0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 16980,
"upload_time": "2024-06-04T08:43:56",
"upload_time_iso_8601": "2024-06-04T08:43:56.175929Z",
"url": "https://files.pythonhosted.org/packages/06/e8/300f944d1b5c82bc809de325c63f2be0bb04555c92151750e8313e377092/qase_pytest-6.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-04 08:43:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "qase-tms",
"github_project": "qase-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "qase-pytest"
}