Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-36597: fix random doctest failure #12776

Merged
merged 1 commit into from Apr 11, 2019
Merged

Conversation

methane
Copy link
Member

@methane methane commented Apr 11, 2019

@vstinner
Copy link
Member

Would you mind to close/reopen the PR to trigger a second Travis CI job, to confirm that it's not a random failure?

@vstinner
Copy link
Member

@vstinner vstinner removed the needs backport to 3.7 label just now

The bot cannot cherry-pick directly the change, since I didn't disable doctest in the 3.7 branch.

@methane methane closed this Apr 11, 2019
@methane methane reopened this Apr 11, 2019
@methane
Copy link
Member Author

methane commented Apr 11, 2019

@vstinner
Copy link
Member

When I test your PR locally, I still get random failures. Commands:

cd Doc
make clean
make venv
LANG= PATH=./venv/bin:$PATH sphinx-build -b doctest -d build/doctrees -D latex_elements.papersize= -q -W -j4 -W . build/doctest ^C

Example of failure:

Warning, treated as error:
**********************************************************************
File "library/statistics.rst", line 126, in default
Failed example:
    fmean([3.5, 4.0, 5.25])
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib64/python3.7/doctest.py", line 1329, in __run
        compileflags, 1), test.globs)
      File "<doctest default[0]>", line 1, in <module>
        fmean([3.5, 4.0, 5.25])
    NameError: name 'fmean' is not defined

My venv has these versions:

$ venv/bin/python -m pip freeze
alabaster==0.7.12
Babel==2.6.0
blurb==1.0.7
certifi==2019.3.9
chardet==3.0.4
docutils==0.14
idna==2.8
imagesize==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
packaging==19.0
Pygments==2.3.1
pyparsing==2.4.0
python-docs-theme==2018.7
pytz==2019.1
requests==2.21.0
six==1.12.0
snowballstemmer==1.2.1
Sphinx==2.0.1
sphinxcontrib-applehelp==1.0.1
sphinxcontrib-devhelp==1.0.1
sphinxcontrib-htmlhelp==1.0.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.2
sphinxcontrib-serializinghtml==1.1.3
urllib3==1.24.1

@methane
Copy link
Member Author

methane commented Apr 11, 2019

make venv is wrong. You used Python 3.7.
make PYTHON=../python venv is needed.

@vstinner
Copy link
Member

I'm very surprised that the job succeed on Travis CI but fail locally. Why Travis CI doesn't get the library/statistics.rst bug for example? Extract of library/statistics.rst where the fail occurred:

.. function:: fmean(data)

   Convert *data* to floats and compute the arithmetic mean.

   This runs faster than the :func:`mean` function and it always returns a
   :class:`float`.  The result is highly accurate but not as perfect as
   :func:`mean`.  If the input dataset is empty, raises a
   :exc:`StatisticsError`.

   .. doctest::

      >>> fmean([3.5, 4.0, 5.25])
      4.25

   .. versionadded:: 3.8

This file doesn't contain "import statistics". How is doctest support to know that fmean() comes from statistics?

@methane
Copy link
Member Author

methane commented Apr 11, 2019

There is "testsetup" directive In library/statistics.rst:

.. testsetup:: *

   from statistics import *
   __name__ = '<doctest>'

@vstinner
Copy link
Member

This file doesn't contain "import statistics". How is doctest support to know that fmean() comes from statistics?

Ah sorry, I looked for "import statistics", but the file contains:

.. testsetup:: *

   from statistics import *
   __name__ = '<doctest>'

I didn't know this markup. The doc can be found at:
https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html

Doc/conf.py also contains:

extensions = [..., 'sphinx.ext.doctest', ...]

doctest_global_setup = '''
try:
    import _tkinter
except ImportError:
    _tkinter = None
'''

@vstinner
Copy link
Member

make venv is wrong. You used Python 3.7.
make PYTHON=../python venv is needed.

Aaaaaah, ok :-) Sorry, I completely misunderstood how sphinx-build picks its Python.

I was confused by this line from .travis.yml:

xvfb-run make -C Doc/ PYTHON=../python SPHINXOPTS="-q -W -j4" doctest

The PYTHON=../python argument is misleading: it's useless, since sphinx-build uses its "own" Python from the virtual environment...

Sorry for the noise.

@methane methane merged commit 57b1a28 into python:master Apr 11, 2019
@methane methane deleted the fix-doctest branch April 11, 2019 08:53
@vstinner
Copy link
Member

Thanks @methane for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants