Skip to main content

pytest Integration

Run your pytest tests as usual and have results, screenshots, and artifacts automatically reported to ProvaLab.io. The plugin integrates deeply with pytest's hook system for seamless reporting.

Install

pip install tms-plugin

Requirements: Python >= 3.9, pytest >= 7.0.0

Configure

1. Set up credentials

You can configure ProvaLab.io via pytest.ini, command-line flags, or a combination of both.

Option A: pytest.ini (recommended for teams)

pytest.ini
[pytest]
tms_enable = true
tms_url = https://tms.yourcompany.com
tms_api_key = your-api-key
tms_organization_id = 1
tms_test_plan_id = 10
tms_environment = staging

Option B: Command-line flags

pytest --tms-enable \
--tms-url=https://tms.yourcompany.com \
--tms-api-key=your-api-key \
--tms-organization-id=1 \
--tms-test-run-id=123

Option C: Mix both (secrets via CLI, config in file)

pytest.ini
[pytest]
tms_enable = true
tms_url = https://tms.yourcompany.com
tms_organization_id = 1
tms_test_plan_id = 10
pytest --tms-api-key=your-api-key
Use --tms-test-plan-id to auto-create runs

If you provide --tms-test-plan-id instead of --tms-test-run-id, the plugin automatically creates a new test run under that plan each time you run tests. This is the recommended approach for CI/CD.

2. Mark your tests with ProvaLab.io case IDs

tests/test_login.py
import pytest

@pytest.mark.tms_case_id(101)
def test_login_with_valid_credentials():
"""Verify user can log in with correct email and password."""
result = login("[email protected]", "password123")
assert result.success is True

@pytest.mark.tms_case_id(102)
def test_login_with_invalid_password():
"""Verify login fails with wrong password."""
with pytest.raises(AuthenticationError):
login("[email protected]", "wrong-password")

@pytest.mark.tms_case_id(103)
def test_login_with_expired_account():
"""Verify expired accounts cannot log in."""
with pytest.raises(AccountExpiredError):
login("[email protected]", "password123")
Tests without @pytest.mark.tms_case_id are skipped

Only tests marked with @pytest.mark.tms_case_id() are reported to ProvaLab.io. Unmarked tests run normally but don't appear in ProvaLab.io.

Run

pytest --tms-enable

You'll see ProvaLab.io output in the terminal summary:

========================= ProvaLab.io Test Results =========================
Test Run ID: 852
Total: 3, Passed: 2, Failed: 1, Blocked: 0, Skipped: 0
Pass Rate: 66.67%
====================================================================

View Results in ProvaLab.io

  1. Open ProvaLab.io and go to your project
  2. Click Test Runs in the sidebar
  3. Find the run named "Pytest Run - 2026-02-20 14:30:00"
  4. Click into it to see individual test results with error tracebacks and screenshots

Advanced Configuration

Screenshot on failure

The plugin automatically captures screenshots when a test fails, if a Selenium WebDriver or Playwright page is available as a fixture:

tests/conftest.py
import pytest
from selenium import webdriver

@pytest.fixture
def driver():
"""Selenium WebDriver fixture -- ProvaLab.io auto-captures screenshot on failure."""
d = webdriver.Chrome()
yield d
d.quit()
tests/test_ui.py
import pytest

@pytest.mark.tms_case_id(201)
def test_dashboard_loads(driver):
driver.get("https://app.yourcompany.com/dashboard")
assert "Dashboard" in driver.title
# If this fails, ProvaLab.io captures a screenshot from the driver automatically

Screenshots are saved to test_screenshots/ by default. Customize with:

pytest --tms-enable --tms-screenshot-dir=./artifacts/screenshots

Video segment tracking

When using Selenium Grid with video recording, the plugin records timestamps for each test so you can seek to specific test executions in the video:

pytest --tms-enable --tms-video-segments

Environment selection

pytest --tms-enable --tms-environment=staging
pytest --tms-enable --tms-environment=production

All command-line options

FlagDefaultDescription
--tms-enablefalseEnable ProvaLab.io reporting
--tms-urlhttp://localhost:8000ProvaLab.io API base URL
--tms-api-key-API key for authentication
--tms-organization-id-Organization ID
--tms-test-run-id-Existing test run ID
--tms-test-plan-id-Test plan ID (creates new run)
--tms-environmentdevEnvironment tag
--tms-capture-screenshotstrueCapture screenshots on failure
--tms-screenshot-dirtest_screenshotsDirectory for screenshots
--tms-video-segmentstrueEnable video segment tracking

Verify It Works

  1. Install the plugin:
pip install tms-plugin
  1. Create a simple test:
tests/test_tms_verify.py
import pytest

@pytest.mark.tms_case_id(1)
def test_verify_tms_integration():
"""Verify ProvaLab.io integration is working."""
assert 1 + 1 == 2
  1. Run it:
pytest tests/test_tms_verify.py \
--tms-enable \
--tms-url=https://tms.yourcompany.com \
--tms-api-key=your-api-key \
--tms-organization-id=1 \
--tms-test-run-id=1
  1. Check the terminal for the ProvaLab.io summary with pass/fail counts
  2. Open ProvaLab.io and confirm the test result appears under your test run
Common issues
  • "Either --tms-test-run-id or --tms-test-plan-id must be provided": You need one of these to tell ProvaLab.io where to report results
  • Tests run but nothing appears in ProvaLab.io: Make sure tests have the @pytest.mark.tms_case_id() marker
  • "Failed to initialize ProvaLab.io plugin": Check that your API key is valid and the URL is reachable