Sometimes I would like to include a pytest test report in a GitHub issue or pull request comment, but do not want to manually reformat the CLI output. 😄
Thankfully, pytest can be extended and customized via plugins. Inspired by the fantastic pytest-html project, I created my new pytest plugin pytest-md for generating Markdown reports for pytest results! 📝
If you find it any useful, I’d love to hear from you via twitter! 😃
Installation
pytest-md is available on PyPI for Python versions 3.6 and newer and can be installed into your enviroment from your terminal via pip:
$ pip install pytest-md
Usage
The following example code produces all of the different pytest test outcomes.
import random
import pytest
def test_failed():
assert "emoji" == "hello world"
@pytest.mark.xfail
def test_xfail():
assert random.random() == 1.0
@pytest.mark.xfail
def test_xpass():
assert 0.0 < random.random() < 1.0
@pytest.mark.skip(reason="don't run this test")
def test_skipped():
assert "pytest-emoji" != ""
@pytest.mark.parametrize(
"name, expected",
[
("Sara", "Hello Sara!"),
("Mat", "Hello Mat!"),
("Annie", "Hello Annie!"),
],
)
def test_passed(name, expected):
assert f"Hello {name}!" == expected
@pytest.fixture
def number():
return 1234 / 0
def test_error(number):
assert number == number
With pytest-md installed, you can now generate a Markdown test report as follows:
$ pytest --md report.md
# Test Report
*Report generated on 25-Feb-2019 at 17:18:29 by [pytest-md]*
[pytest-md]: https://github.com/hackebrot/pytest-md
## Summary
8 tests ran in 0.05 seconds
- 1 failed
- 3 passed
- 1 skipped
- 1 xfailed
- 1 xpassed
- 1 error
pytest-emoji
pytest-md also integrates with pytest-emoji, which allows us to include emojis in the generated Markdown test report:
$ pytest --emoji -v --md report.md
# Test Report
*Report generated on 25-Feb-2019 at 17:18:29 by [pytest-md]* 📝
[pytest-md]: https://github.com/hackebrot/pytest-md
## Summary
8 tests ran in 0.06 seconds ⏱
- 1 failed 😰
- 3 passed 😃
- 1 skipped 🙄
- 1 xfail 😞
- 1 xpass 😲
- 1 error 😡
More information
For more information check out pytest-md on GitHub.