pytest-testrail
raw JSON → 3.1.1 verified Mon Apr 27 auth: no python
A pytest plugin for creating TestRail test runs and adding results automatically. Version 3.1.1 requires Python >=3.10, released under MIT License. Active development with frequent releases.
pip install pytest-testrail Common errors
error pytest: error: unrecognized arguments: --testrail ↓
cause The plugin is not installed or not activated.
fix
Install pytest-testrail: pip install pytest-testrail. Ensure it is in the current environment.
error ModuleNotFoundError: No module named 'pytest_testrail' ↓
cause pytest-testrail is not installed or virtual environment not activated.
fix
Run: pip install pytest-testrail. Check that you are in the correct virtual environment.
error AttributeError: module 'pytest_testrail' has no attribute 'get_testrail_client' ↓
cause Incorrect import path. get_testrail_client is in the fixtures submodule.
fix
Use: from pytest_testrail.fixtures import get_testrail_client
Warnings
breaking In v2.x, the plugin used a different configuration format. v3.x changed the config section name and flattened options. Check existing pytest.ini files. ↓
fix Update pytest.ini: replace [testrail] with [pytest] testrail block or use pytest options.
deprecated The 'testrail' marker without an explicit id may be deprecated in future; always use id parameter. ↓
fix Use @pytest.mark.testrail(id='C123') instead of @pytest.mark.testrail.
gotcha The plugin requires a running TestRail instance; it will fail if the URL is unreachable. Network timeout issues are common. ↓
fix Verify TestRail URL and credentials; use pytest with -s to see debug output.
gotcha If using API key, set password field to the API key; some users mistakenly use a password instead. ↓
fix In config, set password = your_api_key (not your login password).
Imports
- pytest_testrail wrong
from pytest_testrail import *correctimport pytest_testrail - pytest_testrail.fixtures wrong
from pytest_testrail import get_testrail_clientcorrectfrom pytest_testrail.fixtures import get_testrail_client
Quickstart
# conftest.py or test file
import os
import pytest
# Enable plugin via pytest.ini or pyproject.toml
# [pytest]
# testrail =
# url = https://your.testrail.com
# user = your_email
# password = your_password_or_api_key
# project_id = 1
# suite_id = 1
# run_name = Automated Run
# Test case must have testrail id marker
@pytest.mark.testrail(id='C123')
def test_example():
assert 1 + 1 == 2
# Or use dynamic assignment
from pytest_testrail.plugin import TestRail
# Optionally get client
from pytest_testrail.fixtures import get_testrail_client
def test_custom(client=get_testrail_client()):
# Use client directly if needed
assert client
assert True