From a030c200136dbeb1edae3db59ea6bbcce50ff7f8 Mon Sep 17 00:00:00 2001 From: Christian Sandberg Date: Thu, 8 Aug 2024 19:59:52 +0200 Subject: [PATCH 1/3] Add doctest sample --- tests/samples/sample_doctest.txt | 4 ++++ tests/test_samples.py | 1 + 2 files changed, 5 insertions(+) create mode 100644 tests/samples/sample_doctest.txt diff --git a/tests/samples/sample_doctest.txt b/tests/samples/sample_doctest.txt new file mode 100644 index 0000000..c7584d3 --- /dev/null +++ b/tests/samples/sample_doctest.txt @@ -0,0 +1,4 @@ +hello this is a doctest +>>> x = 3 +>>> x +3 diff --git a/tests/test_samples.py b/tests/test_samples.py index f0bc6f5..41f40e6 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -31,6 +31,7 @@ def test_sample_report(args, testdir, pytestconfig): report = "{}/report/{}".format(pytestconfig.rootdir, args[0]) result = testdir.runpytest( *args[1:], + "--doctest-glob", "sample_*.txt", "--template=html1/index.html", "--report=" + report ) From b4740f8ea61dc081738527c47a6fb8afed1bec10 Mon Sep 17 00:00:00 2001 From: Christian Sandberg Date: Thu, 8 Aug 2024 20:18:38 +0200 Subject: [PATCH 2/3] Don't assume all tests are functions --- pytest_reporter_html1/templates/html1/test.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_reporter_html1/templates/html1/test.html b/pytest_reporter_html1/templates/html1/test.html index 4e8884b..a9de263 100644 --- a/pytest_reporter_html1/templates/html1/test.html +++ b/pytest_reporter_html1/templates/html1/test.html @@ -1,5 +1,5 @@ {% block test_content scoped %} -{% if test.item.function.__doc__ %} +{% if test.item.function and test.item.function.__doc__ %}
{{ test.item.function.__doc__|cleandoc|rst|safe }}
From 979aabcea735ce0d8509b6728fb5cde5a6eb396c Mon Sep 17 00:00:00 2001 From: Christian Sandberg Date: Thu, 8 Aug 2024 20:18:47 +0200 Subject: [PATCH 3/3] Make doctest fail --- tests/samples/sample_doctest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/samples/sample_doctest.txt b/tests/samples/sample_doctest.txt index c7584d3..b99fc43 100644 --- a/tests/samples/sample_doctest.txt +++ b/tests/samples/sample_doctest.txt @@ -1,4 +1,4 @@ hello this is a doctest >>> x = 3 >>> x -3 +4