Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Pytest documentation + build tweaks #8026
Conversation
QuLogic
added Documentation Testing
labels
Feb 5, 2017
QuLogic
added this to the
2.1 (next point release)
milestone
Feb 5, 2017
|
Added one more tweak to use |
QuLogic
changed the title from
Pytest tweaks to Pytest documentation + build tweaks
Feb 6, 2017
|
I've added the developer documentation for setting up pytest and removed a few more cases of nose in the setup, package metadata, etc. |
QuLogic
added
to Needs Review in Migrate to `pytest`
Feb 6, 2017
|
Could we document the pytest interface rather than After a quick look at |
| @@ -12,7 +12,6 @@ commands = | ||
| sh -c 'rm -f $HOME/.matplotlib/fontList*' |
| - import pandas as pd | ||
| - except ImportError: | ||
| - pytest.skip("Pandas not installed") | ||
| + pd = pytest.importorskip('pandas') |
dstansby
Feb 6, 2017
Contributor
Is there a minimum required version of pandas needed for the pandas tests to work?
phobson
Feb 6, 2017
Member
It doesn't appear that there is. Creating a Series from a list and DataFrame a from a dictionary of lists/arrays should work with versions of pandas several years old at this point.
| @@ -1,32 +0,0 @@ | ||
| -from __future__ import print_function |
dstansby
Feb 6, 2017
•
Contributor
Also need to get rid of exammples/event_handling/test_mouseclicks.rst
jenshnielsen
Feb 6, 2017
Owner
Isn't that file autogenerated from the example? It's not in version control as far as I can see
| -documentation for supported arguments. Some of the more important ones are given | ||
| -here: | ||
| +Additional arguments are passed on to pytest. See the pytest documentation for | ||
| +supported arguments. Some of the more important ones are given here: |
dstansby
Feb 6, 2017
Contributor
Might be good to put a link to the pytest documents that list supported arguments
| - python tests.py matplotlib.tests.test_simplification:test_clipping | ||
| + python tests.py matplotlib.tests.test_simplification::test_clipping |
dstansby
Feb 6, 2017
Contributor
Is there any point documenting the method where tests have to be installed, if the method below (which doesn't require installed tests) works?
QuLogic
Feb 6, 2017
Member
I don't know; does anyone use this method?
On further though, using non-installed tests might be broken when trying mpl_toolkits tests because they import stuff from matplotlib.tests. I can move things around to get that working again.
| import matplotlib | ||
| matplotlib.test() | ||
| .. hint:: | ||
| - To run the tests you need to install nose and mock if using python 2.7:: | ||
| + To run the tests you need to install pytest and mock if using python 2.7:: |
dstansby
Feb 6, 2017
Contributor
Everything in this hint is covered above, so I think it can just be deleted
QuLogic
added some commits
Feb 3, 2017
|
I updated the documentation to follow the requests here and also moved some bits around so that tests work without being installed. Everything but the determinism test in the SVG backend works (because that one imports itself, which doesn't exist when not installed); not too sure how to fix that one, but it's not a high priority since not-installed tests never worked before. |
NelleV
reviewed
Feb 16, 2017
Here are general comments on the documentation part.
This are minor comments and should not prevent the pull requests from being merged. These are just overall suggestions of improvements.
I'll review the rest of the PR.
| @@ -106,12 +106,10 @@ or example code. | ||
| If you want to try the many demos that come in the matplotlib source | ||
| distribution, download the :file:`*.tar.gz` file and look in the | ||
| :file:`examples` subdirectory. | ||
| -To run the test suite, copy the :file:`lib\\matplotlib\\tests` and | ||
| +To run the test suite, extract the :file:`lib\\matplotlib\\tests` or |
| -more information. Note that the test suite requires nose and on Python 2.7 mock | ||
| -which are not installed by default. Please install with pip or your package | ||
| -manager of choice. | ||
| +more information. Note that the test suite requires pytest and on Python 2.7 |
NelleV
Feb 16, 2017
Contributor
I think this sentence would be better with comas (for the understanding):
Note that the test suite requires pytest and, on Python 2.7, mock.
The "which are not installed by default seems redundant.
I would be happy to push a fix to your branch. Let me know if you prefer this option.
| @@ -30,7 +30,7 @@ requirements: | ||
| - freetype 2.6* | ||
| - msinttypes # [win] | ||
| - cycler >=0.10 | ||
| - - nose | ||
| + - pytest >=3.0.0 |
| - <https://docs.python.org/dev/library/unittest.mock.html>`_ (if python < 3.3), `Ghostscript | ||
| - <https://www.ghostscript.com/>`_, `Inkscape <https://inkscape.org>`_ | ||
| + **Additional dependencies for testing**: pytest_ (version 3.0 or later), | ||
| + mock_ (if python < 3.3), Ghostscript_, Inkscape_ |
dstansby
Feb 19, 2017
Contributor
Python 3 < 3.3 isn't supported but matplotlib, so might make more sense to change this to "if python 2.7"
| -please ignore it while we consolidate our testing to these locations.) | ||
| - | ||
| -.. _nose: https://nose.readthedocs.io/en/latest/ | ||
| +Matplotlib has a testing infrastructure based on pytest_, making it easy to |
NelleV
Feb 16, 2017
Contributor
Here are suggestions:
Matplotlib's testing infrastucture relies on pytest_. Test files are place in [path to the folder], and testing utility functions are in :mod:`matplotlib.testing`.
I'd drop the "making it easy to write new tests", as this is a judgement call that I also totally disagree with.
I'd also remove the "There is other old testing cruft around…"
QuLogic
Feb 18, 2017
Member
Changed; also switched to the file paths instead of modules since we're talking about developers who probably want to edit the existing files.
| - information | ||
| - - `pep8 <http://pep8.readthedocs.io/en/latest>`_ to test coding standards | ||
| + - pytest-cov_ to collect coverage information | ||
| + - pytest-pep8_ to test coding standards |
NelleV
Feb 16, 2017
Contributor
I would add all the optional dependencies here:
- pytest-xdist
- pytest-timeout_
| -Running the tests is simple. Make sure you have nose installed and run:: | ||
| +Running the tests is simple. Make sure you have pytest installed and run:: | ||
| + | ||
| + py.test |
| + | ||
| + py.test | ||
| + | ||
| +or:: | ||
| python tests.py |
| - python tests.py matplotlib.tests.test_simplification:test_clipping | ||
| + py.test lib/matplotlib/tests/test_simplification.py::test_clipping |
| - python tests.py matplotlib.tests.test_simplification:test_clipping | ||
| + py.test lib/matplotlib/tests/test_simplification.py::test_clipping | ||
| + | ||
| +or, if tests are installed, a dot-separated path to the module, optionally |
NelleV
Feb 16, 2017
Contributor
I would remove this section. We only need to document one way to do this.
| + | ||
| +An alternative implementation that does not look at command line arguments | ||
| +and works from within Python is to run the tests from the Matplotlib library | ||
| +function :func:`matplotlib.test`:: | ||
| import matplotlib | ||
| matplotlib.test() |
NelleV
Feb 16, 2017
Contributor
I'd remove this section from our documentation. I think we should document (and have) only one way to run the tests.
attn @tacaswell (as I believe Thomas will disagree with me on that one).
| - """ | ||
| - fig = figure() | ||
| - ... | ||
| +Tests that have side effects that need to be cleaned up, such as created |
NelleV
Feb 16, 2017
Contributor
That paragraph is very unclear to me. Here is a suggestions.
"Some tests have side effects that need to be cleaned up after their execution (such as created figures or modifiec rc params). The pytest fixture XXX will automatically clean these up:
add short example showing how to use the fixture"
QuLogic
Feb 18, 2017
Member
There's no need for an example because the fixture gets used automatically; I've swapped the text around as suggested.
| @@ -29,13 +29,13 @@ connect your function to the event manager, which is part of the | ||
| example that prints the location of the mouse click and which button | ||
| was pressed:: | ||
| - fig = plt.figure() | ||
| - ax = fig.add_subplot(111) | ||
| + fig, ax = plt.subplots() |
|
Thanks for doing this. This is very helpful. Both the docs and switching to pytest. There is a bit of a learning curve with it, but it seems to be much more flexible than nose. |
|
I've removed an extra 3.5 build on Travis because it's pretty redundant; hopefully that will get us to finished CI just a little bit faster. |
NelleV
changed the title from
Pytest documentation + build tweaks to [MRG+1] Pytest documentation + build tweaks
Feb 18, 2017
|
LGTM |
| -An alternative implementation that does not look at command line | ||
| -arguments works from within Python is to run the tests from the | ||
| -matplotlib library function :func:`matplotlib.test`:: | ||
| + PYTHONHASHSEED=0 py.test --verbose -n 5 |
anntzer
Feb 19, 2017
Contributor
Can we just specify a minimum version of pytest-xdist where this is no longer an issue? It looks like it is related to https://bitbucket.org/pytest-dev/pytest/issues/346/pytest-xdist-and-python-33-is-sort-of, which has been resolved in 2013.
QuLogic
Feb 19, 2017
Member
Unfortunately, it's not fixed yet: pytest-dev/pytest#920
I just PR'd the same fix to the pandas build, so I know that recent versions still don't work.
QuLogic
requested a review
from tacaswell
Feb 19, 2017
dstansby
approved these changes
Feb 19, 2017
I think this looks ready to go! I've just left a couple of comments for things that might need tweaking in the docs; let me know once you've read and/or changed them, and I will merge.
| + `mock <https://pypi.python.org/pypi/mock>`_, Pillow, MiKTeX, GhostScript, | ||
| + ffmpeg, avconv, mencoder, ImageMagick, and `Inkscape | ||
| + <https://inkscape.org/>`_; | ||
| + * run ``py.test path\\to\\tests\\directory``. |
dstansby
Feb 19, 2017
Contributor
- According to pytest-dev/pytest#1629 (comment) ,
pytestis preferred overpy.testas of 3.0 - I don't think you need the extra
path\\to\\tests\\directorybit; if you do then line 23 ofREADME.rstshould be made consistent
QuLogic
Feb 20, 2017
Member
This is about separate uninstalled tests; line 23 in README.rst is about running from the full source directory.
| @@ -20,17 +20,16 @@ Testing | ||
| After installation, you can launch the test suite:: | ||
| - python tests.py | ||
| + py.test |
| - <https://docs.python.org/dev/library/unittest.mock.html>`_ (if python < 3.3), `Ghostscript | ||
| - <https://www.ghostscript.com/>`_, `Inkscape <https://inkscape.org>`_ | ||
| + **Additional dependencies for testing**: pytest_ (version 3.0 or later), | ||
| + mock_ (if python < 3.3), Ghostscript_, Inkscape_ |
dstansby
Feb 19, 2017
Contributor
Python 3 < 3.3 isn't supported but matplotlib, so might make more sense to change this to "if python 2.7"
| -Running the tests is simple. Make sure you have nose installed and run:: | ||
| +Running the tests is simple. Make sure you have pytest installed and run:: | ||
| + | ||
| + py.test |
| +or, if tests are installed, a dot-separated path to the module, optionally | ||
| +followed by the function separated by two colons, such as:: | ||
| + | ||
| + py.test --pyargs matplotlib.tests.test_simplification::test_clipping | ||
| If you want to run the full test suite, but want to save wall time try |
dstansby
changed the title from
[MRG+1] Pytest documentation + build tweaks to Pytest documentation + build tweaks
Feb 20, 2017
|
Since all the lines I commented on are technically true and easily changed later, I'm going to merge (finally!), thanks for all the work on this @QuLogic |
QuLogic commentedFeb 5, 2017
•
edited
I've added the developer documentation for setting up pytest and removed a few more cases of nose in the setup, package metadata, etc.
For the tweaks:
tests.pywhen run with a module path instead of a file path.image_comparisonbecause that decorator expects all figures when it's done to correspond to figures from the test, but if never checks for/ignores any already open figures.test_mouseclicks.pyexample because it's getting collected and run by pytest and since it's not really written as a test it causes an extra figure to be opened which breaks any image tests if run directly (modulo the previous fix.) Also copy the use ofevent.dblclickinto the documentation so it's not gone completely.importorskipeverywhere so that the skip reasons are always the same, since it's used in some places and not others.Fixes #8015.