Coveralls Python

4.1.0 · active · verified Sat Apr 11

Coveralls Python (coveralls-python) is a Python library that provides seamless integration with coverage.py to send code coverage statistics to Coveralls.io. It supports various Continuous Integration (CI) systems and allows for detailed online reporting of test coverage for Python projects. Currently at version 4.1.0, it is actively maintained with several releases per year to keep up with Python and `coverage.py` updates.

Warnings

Install

Quickstart

After installing `coveralls` and collecting coverage data with `coverage.py` (e.g., by running `coverage run -m pytest`), you can submit the results to Coveralls.io. For non-CI environments or unsupported CI systems, ensure the `COVERALLS_REPO_TOKEN` environment variable is set.

import os

# Simulate running tests with coverage.py
# In a real scenario, you'd run your tests like:
# coverage run -m pytest
# For this example, we assume coverage.py has already generated .coverage data.

# Set the Coveralls repository token (replace with your actual token or use env var)
# This is often handled automatically in supported CI environments.
# For local testing or unsupported CIs, ensure COVERALLS_REPO_TOKEN is set.
# You can find this token on your project's dashboard in coveralls.io.
os.environ['COVERALLS_REPO_TOKEN'] = os.environ.get('COVERALLS_REPO_TOKEN', 'your_coveralls_repo_token_here')

# Run the coveralls command-line tool
import subprocess
try:
    # Typically, you'd run 'coverage run -m pytest' first, then 'coveralls'
    # For this example, we simulate the submission step after coverage data is assumed to exist.
    print("Attempting to submit coverage to Coveralls.io...")
    # The actual command would be: subprocess.run(["coveralls"], check=True)
    # We'll mock the output for a runnable example without actual submission.
    mock_output = "Submitting coverage to coveralls.io...\nCoverage submitted! Job #123.456 https://coveralls.io/jobs/1234567890"
    print(mock_output)
    # For an actual run:
    # result = subprocess.run(["coveralls"], capture_output=True, text=True, check=True)
    # print(result.stdout)
    # print(result.stderr)
except subprocess.CalledProcessError as e:
    print(f"Error submitting coverage: {e.stderr}")
except FileNotFoundError:
    print("Error: 'coveralls' command not found. Ensure coveralls is installed and in your PATH.")

view raw JSON →