Qase API Client
The Qase API Client provides a Python interface for interacting with the Qase TestOps API (v1). It allows programmatic access to manage test cases, test runs, defects, and other TestOps entities. The current version is 2.0.6, and it's part of a larger monorepo with frequent, modular releases across various Qase Python integrations.
Common errors
-
ImportError: No module named 'qase.api_client'
cause Incorrect top-level package name. The Qase API client is installed under the `qaseio` namespace.fixChange your import statements from `from qase...` to `from qaseio...`. For example: `from qaseio.api_client.configuration import Configuration`. -
qaseio.api_client.exceptions.ApiException: (401) Unauthorized
cause The provided API token is invalid, expired, or missing. Or, the token does not have the necessary permissions for the requested operation.fixVerify your Qase API Token in your Qase TestOps account settings. Ensure it's correctly passed in the `Configuration` object: `api_key={'TokenAuth': 'YOUR_VALID_TOKEN'}`. -
AttributeError: 'ApiClient' object has no attribute 'cases_api'
cause You are trying to call an API method directly on the `ApiClient` instance. The `ApiClient` is a low-level HTTP client; specific API operations are exposed through dedicated API client classes (e.g., `CasesApi`, `RunsApi`).fixInstantiate the relevant API client class using the `ApiClient` object: `cases_api = CasesApi(api_client)`. Then call methods on `cases_api`, e.g., `cases_api.get_cases(...)`.
Warnings
- gotcha The `qase-python` GitHub repository is a monorepo containing multiple packages (e.g., `qase-api-client`, `qase-api-v2-client`, `qase-pytest`, `qase-robotframework`). Ensure you install `qase-api-client` specifically if you intend to use the base API client, as other packages may have different dependencies or purposes.
- gotcha Authentication uses an 'API Token' which is mapped to `api_key` in the generated client's `Configuration` object. The parameter name for the Qase API is `TokenAuth`.
- breaking Qase has both `qase-api-client` (v1) and `qase-api-v2-client` (v2) packages. While they currently share the same version number (2.0.x) in the monorepo, they target different API versions. Using the wrong client for a specific API version can lead to unexpected behavior or missing functionality.
Install
-
pip install qase-api-client
Imports
- Configuration
from qase.api_client.configuration import Configuration
from qaseio.api_client.configuration import Configuration
- ApiClient
from qaseio.api_client import ApiClient
from qaseio.api_client.api_client import ApiClient
- CasesApi
from qaseio.api_client.api.cases_api import CasesApi
Quickstart
import os
from qaseio.api_client.configuration import Configuration
from qaseio.api_client.api_client import ApiClient
from qaseio.api_client.api.cases_api import CasesApi
QASE_TOKEN = os.environ.get('QASE_TOKEN', 'YOUR_QASE_TOKEN')
QASE_PROJECT_CODE = os.environ.get('QASE_PROJECT_CODE', 'PRJ') # e.g., 'PRJ'
if QASE_TOKEN == 'YOUR_QASE_TOKEN' or QASE_PROJECT_CODE == 'PRJ':
print("Please set QASE_TOKEN and QASE_PROJECT_CODE environment variables or replace placeholders.")
else:
try:
# Configure API key authorization: TokenAuth
configuration = Configuration(
host="https://api.qase.io/v1",
api_key={"TokenAuth": QASE_TOKEN}
)
# Create an API client
with ApiClient(configuration) as api_client:
# Create an instance of the API you want to use
cases_api = CasesApi(api_client)
# Example: Get all cases for a project
response = cases_api.get_cases(QASE_PROJECT_CODE)
print(f"Successfully retrieved {len(response.result.entities)} cases.")
# print(response.to_dict())
except Exception as e:
print(f"An error occurred: {e}")