sphinx-doc/sphinx

sphinx.ext.doctest should ensure that output is patched before importing the target

Open

#3.891 geöffnet am 25. Juni 2017

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)Python (1.985 Forks)batch import
builderextensions:doctesthelp wantedtype:proposal

Repository-Metriken

Stars
 (5.625 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 10T 11h) (11 gemergte PRs in 30 T)

Beschreibung

Problem

  • sphinx.ext.doctest will import the target before making sure that docutils has patched sys.stdout and sys.stderr with _SpoofOut objects. If the target module has already gotten a reference to stdout and stderr and writes to them doctests will fail.

Procedure to reproduce the problem

doctest a function like:

def f(stdout=sys.stdout):
    """
    .. testcode::
        f()
    .. testoutput::
        hello
    """
    stdout.write("hello")

Expected results

a successful doctest, where sys.stdout should be patched before the module under test is imported

Actual results

The output goes to the real sys.stdout, and the doctest fails claiming no output was produced

Contributor Guide