Skip to content

Commit

Permalink
Fix failed doctest status reporting (allure-framework#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
delatrie authored Nov 24, 2022
1 parent ed3a676 commit 3f113fe
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
15 changes: 12 additions & 3 deletions allure-pytest/src/listener.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import doctest
import allure_commons
from allure_commons.utils import escape_non_unicode_symbols
from allure_commons.utils import now
Expand Down Expand Up @@ -185,9 +186,9 @@ def pytest_runtest_makereport(self, item, call):
status_details = StatusDetails(
message=message,
trace=trace)
if (status != Status.SKIPPED
and not (call.excinfo.errisinstance(AssertionError)
or call.excinfo.errisinstance(pytest.fail.Exception))):

exception = call.excinfo.value
if (status != Status.SKIPPED and _exception_brokes_test(exception)):
status = Status.BROKEN

if status == Status.PASSED and hasattr(report, 'wasxfail'):
Expand Down Expand Up @@ -305,3 +306,11 @@ def _test_fixtures(item):
fixturedefs.extend(fixturedefs_pytest)

return fixturedefs


def _exception_brokes_test(exception):
return not isinstance(exception, (
AssertionError,
pytest.fail.Exception,
doctest.DocTestFailure
))
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,46 @@ def some_func():
has_test_case("test_pytest_doctest.some_func",
with_status("passed"))
)


@allure.feature("Integration")
def test_pytest_doctest_failed(allured_testdir):
allured_testdir.testdir.makepyfile('''
def some_func():
"""
>>> some_func()
True
"""
return not True
''')

allured_testdir.run_with_allure("--doctest-modules")

assert_that(
allured_testdir.allure_report,
has_test_case(
"test_pytest_doctest_failed.some_func",
with_status("failed")
)
)


@allure.feature("Integration")
def test_pytest_doctest_broken(allured_testdir):
allured_testdir.testdir.makepyfile('''
def some_func():
"""
>>> raise ValueError()
"""
''')

allured_testdir.run_with_allure("--doctest-modules")

assert_that(
allured_testdir.allure_report,
has_test_case(
"test_pytest_doctest_broken.some_func",
with_status("broken")
)
)

0 comments on commit 3f113fe

Please sign in to comment.