|
1 |
| -import doctest |
2 | 1 | import operator
|
3 | 2 | from decimal import Decimal
|
4 | 3 | from fractions import Fraction
|
|
11 | 10 | inf, nan = float("inf"), float("nan")
|
12 | 11 |
|
13 | 12 |
|
14 |
| -class MyDocTestRunner(doctest.DocTestRunner): |
15 |
| - def __init__(self): |
16 |
| - doctest.DocTestRunner.__init__(self) |
| 13 | +@pytest.fixture |
| 14 | +def mocked_doctest_runner(monkeypatch): |
| 15 | + import doctest |
17 | 16 |
|
18 |
| - def report_failure(self, out, test, example, got): |
19 |
| - raise AssertionError( |
20 |
| - "'{}' evaluates to '{}', not '{}'".format( |
21 |
| - example.source.strip(), got.strip(), example.want.strip() |
| 17 | + class MockedPdb: |
| 18 | + def __init__(self, out): |
| 19 | + pass |
| 20 | + |
| 21 | + def set_trace(self): |
| 22 | + raise NotImplementedError("not used") |
| 23 | + |
| 24 | + def reset(self): |
| 25 | + pass |
| 26 | + |
| 27 | + def set_continue(self): |
| 28 | + pass |
| 29 | + |
| 30 | + monkeypatch.setattr("doctest._OutputRedirectingPdb", MockedPdb) |
| 31 | + |
| 32 | + class MyDocTestRunner(doctest.DocTestRunner): |
| 33 | + def report_failure(self, out, test, example, got): |
| 34 | + raise AssertionError( |
| 35 | + "'{}' evaluates to '{}', not '{}'".format( |
| 36 | + example.source.strip(), got.strip(), example.want.strip() |
| 37 | + ) |
22 | 38 | )
|
23 |
| - ) |
| 39 | + |
| 40 | + return MyDocTestRunner() |
24 | 41 |
|
25 | 42 |
|
26 | 43 | class TestApprox:
|
@@ -411,13 +428,14 @@ def test_numpy_array_wrong_shape(self):
|
411 | 428 | assert a12 != approx(a21)
|
412 | 429 | assert a21 != approx(a12)
|
413 | 430 |
|
414 |
| - def test_doctests(self): |
| 431 | + def test_doctests(self, mocked_doctest_runner): |
| 432 | + import doctest |
| 433 | + |
415 | 434 | parser = doctest.DocTestParser()
|
416 | 435 | test = parser.get_doctest(
|
417 | 436 | approx.__doc__, {"approx": approx}, approx.__name__, None, None
|
418 | 437 | )
|
419 |
| - runner = MyDocTestRunner() |
420 |
| - runner.run(test) |
| 438 | + mocked_doctest_runner.run(test) |
421 | 439 |
|
422 | 440 | def test_unicode_plus_minus(self, testdir):
|
423 | 441 | """
|
|
0 commit comments