Skip to main content

Qase Pytest Plugin for Qase TestOps and Qase Report

Project description

Qase Pytest Plugin

License

Installation

pip install qase-pytest

Upgrade from 4.x to 5.x

A new version of qase-pytest reporter has breaking changes. Follow these guide that will help you to migrate to a new version.

Configuration

Qase Pytest Plugin can be configured in multiple ways:

  • using a config file qase.config.json
  • using environment variables
  • using CLI options

All configuration options are listed in the following doc: Configuration.

Example: qase.config.json

{
	"mode": "testops", 
	"fallback": "report",
	"report": {
		"driver": "local",
		"connection": {
			"local": {
				"path": "./build/qase-report",
				"format": "json" 
			}
		}
	},
	"testops": {
		"bulk": true,
		"api": {
			"token": "YOUR_API_TOKEN",
			"host": "qase.io"
		},
		"run": {
            "id": 1,
			"title": "Test run title",
			"complete": true
		},
        "plan": {
            "id": 1
        },
		"defect": true,
		"project": "YOUR_PROJECT_CODE",
		"chunk": 200
	},
	"framework": {
		"pytest": {
			"capture": {
				"logs": true,
				"http": true
			}
		}
	},
	"environment": "local"
}

Usage

Link tests with test cases in Qase TestOps

To link tests in code with tests in Qase TestOps you can use predefined decorators:

from qaseio.pytest import qase

@qase.id(13)
@qase.title("My first test")
@qase.fields(
    ("severity", "critical"),
    ("priority", "hight"),
    ("layer", "unit"),
    ("description", "Try to login in Qase TestOps using login and password"),
    ("description", "*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

If you want to exclude a particular test from the report, you can use the @qase.ignore decorator:

from qaseio.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

In order to capture network logs, you need to enable the http option in the capture section of the framework section in the config file.

Qase Pytest reporter will capture all requests and responses and save as a test step automatically.

Add attachments to test results

When you need to push some additional information to server you could use attachments:

import pytest
from qaseio.pytest import qase

@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')
    qase.attach((logs, "text/plain", "browser.log"))
    driver.quit()

@qase.title("My first test")
def test_example_1():
    qase.attach("/path/to/file", "/path/to/file/2")
    qase.attach(
        ("/path/to/file/1", "application/json"),
        ("/path/to/file/3", "application/xml"),
    )

@qase.id(12)
def test_example_2(driver):
    qase.attach((driver.get_screenshot_as_png(), "image/png", "result.png"))

You could pass as much files as you need.

Also you should know, that if no case id is associated with current test in pytest - attachment would not be uploaded:

import pytest
from qaseio.pytest import qase

@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')
    # This would do nothing, because last test does not have case id link
    qase.attach((logs, "text/plain", "browser.log"))
    driver.quit()

def test_example_2(driver):
    # This would do nothing
    qase.attach((driver.get_screenshot_as_png(), "image/png", "result.png"))

Linking code with steps

It is possible to link test step with function, or using context.

from qaseio.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)

Sending tests to existing testrun

Testrun in TestOps will contain only those test results, which are presented in testrun, but every test would be executed.

pytest \
    --qase-mode=testops \
    --qase-testops-api-token=<your api token here> \
    --qase-testops-project=PRJCODE \ # project, where your testrun exists in
    --qase-testops-run-id=3 # testrun id

Creating test run base on test plan (selective launch)

Create new testrun base on testplan. Testrun in Qase TestOps will contain only those test results. qase-pytest supports selective execution

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

Creating new testrun according to current pytest run

If you want to create a new test run in Qase TestOps for each execution, you can simply skip --qase-testops-run option. If you want to provide a custom name for this run, you can add an option --qase-testops-run-title

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

Project details


Release history Release notifications | RSS feed

This version

5.0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qase-pytest-5.0.2.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qase_pytest-5.0.2-py2.py3-none-any.whl (16.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file qase-pytest-5.0.2.tar.gz.

File metadata

  • Download URL: qase-pytest-5.0.2.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.17

File hashes

Hashes for qase-pytest-5.0.2.tar.gz
Algorithm Hash digest
SHA256 4c5f5be03c80cd36ce48ca4afbbf6665b58734669d98e0bc9a58914add2c25c8
MD5 7d55c35c40a5f8356eb6f91f2b746b62
BLAKE2b-256 fa18c560a6f3692bb9a3ace1172fa536312e021fb565abd635af5f1e27ed4ed1

See more details on using hashes here.

File details

Details for the file qase_pytest-5.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: qase_pytest-5.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.17

File hashes

Hashes for qase_pytest-5.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ee6fb84b469960ccf22f78017f727b35a9678d09edab0ce6690034d156ceb50b
MD5 869589eeacaa4282e56ffbe85cd6d53a
BLAKE2b-256 0e4ab7657e0c42a28a28127a72ca38bd52be3469ffb90caae74a944f2641ccf3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page