Skip to content

Commit 2e0ebc7

Browse files
committed
Fix doctest exceptions not being reported as pytest failures
1 parent f99158d commit 2e0ebc7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/flint/test/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def run_doctests(tests, verbose=False):
5353
runner = doctest.DocTestRunner()
5454
for module, test_set in tests:
5555
if test_set:
56-
print(f"{module}...", end="", flush=True)
56+
print(f"{module}...", end="" if not verbose else "\n", flush=True)
5757
for test in test_set:
5858
if verbose:
5959
print("\tTesting:", test.name)

src/flint/test/test_docstrings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ def report_failure(self, out, test, example, got):
5151
pytrace=False,
5252
)
5353

54+
def report_unexpected_exception(self, out, test, example, exc_info):
55+
pytest.fail(
56+
"\n".join([
57+
f"{test.name}, line: {test.lineno}",
58+
"Failed example:",
59+
f"\t{example.source.strip()}",
60+
"Exception raised:",
61+
doctest._indent(doctest._exception_traceback(exc_info))
62+
]),
63+
pytrace=False,
64+
)
65+
5466
runner = PyTestDocTestRunner()
5567

5668
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)