Skip to content

Instantly share code, notes, and snippets.

@t2y
Created July 24, 2012 02:43
Show Gist options
  • Save t2y/3167682 to your computer and use it in GitHub Desktop.
Save t2y/3167682 to your computer and use it in GitHub Desktop.
simple plugin for shelldoctest with pytest, though this script reports only its result
import pytest
import shelldoctest
# use this if you run only shelldoctest
#def pytest_addoption(parser):
# parser.addoption("--shelldoctest", action="store_true",
# help="run shell-doctest")
#
#def pytest_runtest_setup(item):
# if not isinstance(item, item.Function):
# return
# if item.config.option.shelldoctest \
# and not hasattr(item.obj, 'shelldoctest'):
# pytest.skip("test with shelldoctest only")
def pytest_generate_tests(metafunc):
if hasattr(metafunc.function, "shelldoctest"):
result = shelldoctest.testmod(metafunc.module)
metafunc.parametrize("result", [result])
import pytest
@pytest.mark.shelldoctest
def test_sampletest(result):
"""
$ echo TEST
TEST
[#1]
$ echo TEST1
TEST1
[#2]
$ echo TEST2
TEST3 Failed!!!
"""
assert result.failed == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment