-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Pytest documentation + build tweaks #8026
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
Conversation
Added one more tweak to use |
I've added the developer documentation for setting up pytest and removed a few more cases of nose in the setup, package metadata, etc. |
14598ad
to
61bb7bf
Compare
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*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add python version 3.6 to envlist
above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
import pandas as pd | ||
except ImportError: | ||
pytest.skip("Pandas not installed") | ||
pd = pytest.importorskip('pandas') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a minimum required version of pandas needed for the pandas tests to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to get rid of exammples/event_handling/test_mouseclicks.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that file autogenerated from the example? It's not in version control as far as I can see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️ so it is
doc/devel/testing.rst
Outdated
|
||
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:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything in this hint is covered above, so I think it can just be deleted
doc/devel/testing.rst
Outdated
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to put a link to the pytest documents that list supported arguments
doc/devel/testing.rst
Outdated
|
||
python tests.py matplotlib.tests.test_simplification:test_clipping | ||
python tests.py matplotlib.tests.test_simplification::test_clipping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any point documenting the method where tests have to be installed, if the method below (which doesn't require installed tests) works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Since this decorator assumes that the figures available after are the ones to check, it should close any existing figures or it will get the wrong count.
The name is getting collected as a test by pytest when it isn't one, and it isn't much of an example anyway.
It's used in some places, but not all.
This may or may not become a requirement in the future.
* Check for installed test data only if testing installed package. * Remove relative import out of tests. * Replace assert_str_equal with plain assert (pytest does diffing already).
61bb7bf
to
4fd85f1
Compare
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
INSTALL
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split things into bullet points; hopefully that's clearer.
README.rst
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
@@ -30,7 +30,7 @@ requirements: | |||
- freetype 2.6* | |||
- msinttypes # [win] | |||
- cycler >=0.10 | |||
- nose | |||
- pytest >=3.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
<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_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python 3 < 3.3 isn't supported but matplotlib, so might make more sense to change this to "if python 2.7"
doc/devel/testing.rst
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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…"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed; also switched to the file paths instead of modules since we're talking about developers who probably want to edit the existing files.
|
||
python tests.py matplotlib.tests.test_simplification:test_clipping | ||
py.test lib/matplotlib/tests/test_simplification.py::test_clipping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
doc/devel/testing.rst
Outdated
""" | ||
fig = figure() | ||
... | ||
Tests that have side effects that need to be cleaned up, such as created |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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. |
* Prefer py.test over tests.py * Remove redundant hint * Add link to further pytest documentation * Tweak some sentence structure
The only difference between the two 3.5 builds is one uses tests.py and the other uses py.test. But the 2.7, 3.4, and macOS builds all use tests.py, to this is a waste of resources.
4fd85f1
to
29c1308
Compare
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. |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- According to Introduce pytest command as recommended entry point pytest-dev/pytest#1629 (comment) ,
pytest
is preferred overpy.test
as of 3.0 - I don't think you need the extra
path\\to\\tests\\directory
bit; if you do then line 23 ofREADME.rst
should be made consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment about py.test
vs. pytest
<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_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment about py.test
vs. pytest
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "wall time"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time on a clock on the wall, as opposed to cpu time.
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 👍 |
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.py
when run with a module path instead of a file path.image_comparison
because 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.py
example 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.dblclick
into the documentation so it's not gone completely.importorskip
everywhere so that the skip reasons are always the same, since it's used in some places and not others.Fixes #8015.