pytest-md-report

0.7.0 · active · verified Thu Apr 16

pytest-md-report is a pytest plugin designed to generate test outcomes reports formatted as markdown tables. It extends pytest's functionality by providing various command-line options and a programmatic interface to produce detailed, customizable reports. The library is actively maintained, with frequent updates to support new Python and pytest versions, currently at version 0.7.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use pytest-md-report via the command line to generate a Markdown report. It creates a dummy test file, runs pytest with the `--md-report` flag to enable reporting, `--md-report-output` to specify an output file, and `--md-report-tee` to show the report on the console as well. The generated Markdown report will be saved as `report.md`.

import pytest
import os

def test_example_success():
    assert True

def test_example_failure():
    assert False

def test_example_skipped():
    pytest.skip("demonstrating skip")

# Create a dummy test file
with open("test_example.py", "w") as f:
    f.write("""
import pytest

def test_pass():
    assert 1 + 1 == 2

def test_fail():
    assert 1 + 1 == 3

@pytest.mark.skip(reason='demonstrating skip')
def test_skip():
    assert True
    """
)

# Run pytest with md-report options
# This will generate 'report.md' in the current directory
# and also output to stdout due to --md-report-tee

# Using os.system for demonstration; in a real script, prefer pytest.main()
# For security, avoid os.system with untrusted input.
print("\n--- Running tests and generating report ---")
os.system("pytest --md-report --md-report-output=report.md --md-report-tee test_example.py")

print("\n--- Report generated: report.md ---")
print(open("report.md").read())

# Clean up
os.remove("test_example.py")
os.remove("report.md")

view raw JSON →