Repository navigation
Migration to Py.test testing framework #6731
Copy link
Copy link
Closed
Labels
Description
This task has been started in PR #5405, but ended without success, so I have decided to split it to multiple stages:
- Make
pytestcompatible with the current test suite- Add support of unitest-like fixtures (
setUpand other methods) on classes not derived fromunitest.UnitTest(fixed with 8b64294) - Add support of
image_comparisonandknownfailifdecorator (fixed with bbaf7dc) - Fix
raise KnownFailureTestproblems (PR Add Py.test testing framework support #6730)-
ImageComparisonTest.test -
test_axes.test_formatter_large_small -
test_backend_pgf.compare_figure -
test_animation.check_save_animation -
test_coding_standards.test_pep8_conformance_examples
-
-
test_basicleaks tests fromnumpyinto global scope withfrom pylab import *(fixed with 30caf00) - Solve strange failures on several tests
-
test_subplots.test_subplots_offsettext(PR Missingcleanupdecorator intest_subplots.test_exceptions#6741) -
test_axes.test_eventplot_problem_kwargs(PR Fixed warnings catching and counting withwarnings.catch_warnings#6761) -
test_pickle.test_complete(PR Fixed brokentest_pickle.test_completetest #6840)
-
- Ensure that pytest collects all the tests (6150/6150) (actually nose shows 6151 because it counts
lib/matplotlib/tests/test_delaunay.py::make_all_2d_testfuncsas a test)
- Add support of unitest-like fixtures (
- Migration to pytest
- Add new build under
allow_failureswith pytest- Appveyor
- Travis
- Use
pytest-covfor coverage reports
- Replace nose in all builds with pytest
- Add new build under
- Post-migration
- Rename
setUp->setup_methodand other methods topytestanalogs- Do not inherit tests from
unitest.UnitTestclass - Remove
setUp/tearDownworkaround
- Do not inherit tests from
- Rewrite
image_comparisondecorator (currently it slowdowns the collection phase due to baseline images copying) or usepytest-mplplugin (needs some improvements, see paragraph below) - Rewrite all assertations to pure
assert - Get away from
cleanupdecorator - Replace
knownfailifwithmark.xfail - Replace
raise nose.SkipTest(...)withxfail(...)call ormark.skipifdecorator
- Rename
- Enhancements
- Replace
setup_methodand etc methods with fixtures -
Rewritetest_delaunay.make_all_2d_testfuncs - Use
pytest-pep8plugin instead oftest_coding_standards -
Usepytest-mockplugin instead ofmockandunittest.mock
- Replace
Tests entry point (raised in #5405 (comment))
I think that running tests with simple py.test command is better than python tests.py, but there are unused tests which will run that way. Solutions:
- A. Get them away from pytest's sight with:
-
Remove unused tests (test_sankey,test_skew,test_ttconv, andtest_usetexfromlib/matplotlib/tests) - Rename
test_only.py(tosetup_test_only.pyprobably)
-
- B. Make filter for collection phase.
- Implement whitelist
- Implement blacklist
I have tried both ways and they work, so what to choose is up to you.
py.test --collect-filter=nonepy.test --collect-filter=blacklistpy.test --collect-filter=whitelist
Currently --collect-filter=whitelist is default (to follow same politics as nose does currently).
Image comparison decorator
Why do we have to rewrite image_comparison decorator? Because pytest-mpl plugin in the current state ("as is") is not usable for matplotlib:
- + supports
savefig_kwargs - + supports
tolerance - ‒ need to supply
baseline_dirin every decorator - ‒ does not support image format conversion
- ‒ need something to do with
freetype_version,remove_text, andstyle
Reactions are currently unavailable
Activity
story645 commentedon Jul 12, 2016
As someone who's a big fan of these, what's the rational? Unlike nose, it's part of the standard library and it doesn't seem like it's likely to be deprecated.
QuLogic commentedon Jul 12, 2016
There are converters for nose and unittest, though they aren't totally perfect.
story645 commentedon Jul 12, 2016
Yeah, I guess my question is "will pytest not run unittest" tests? Like I understand dumping nose 'cause it's deprecated, but I don't get the issue with unittest unless it explicitly won't work with pytest
Kojoley commentedon Jul 12, 2016
They will work and they are working (pytest handles them with some internal loader hacking in
_pytest.unitest). But it is useless import of a module that actuality does not used, and you can do same and even more more with pytesttacaswell commentedon Jul 14, 2016
We would work with @astrofrog to get the features we need in
pytest-mpl.jenshnielsen commentedon Jul 14, 2016
@tacaswell are you sure we want to do that. It's the opposite of what @mdboom suggested in #5405
astrofrog commentedon Jul 14, 2016
@tacaswell - I'd be happy to chat about this at SciPy!
astrofrog commentedon Jul 14, 2016
Regarding the negatives for pytest-mpl:
Actually this is not quite correct - there is a default value which is a folder called
baselinerelative to the test. I can also easily add a global setting.I don't think there's any reason we can't add all this, and I don't think it should be that difficult. I'd love to work with you all to make pytest-mpl suitable for matplotlib! (these are all features I would find useful for other projects I use pytest-mpl for)
QuLogic commentedon Oct 8, 2016
Another point: we need to get rid of the
yield-based tests; they are causing tons of warning in the pytest built.QuLogic commentedon Nov 16, 2016
The
yield-based tests are fixed, but do we still have a problem of not being able to usexdist?Kojoley commentedon Nov 16, 2016
It looks like we can. At least I have tried and it is good. PR #7468 is opened.
jnothman commentedon Mar 16, 2017
In my own project using pytest, attempting to use
@image_comparisonseems to make the test undetected by pytest. This seems to contradict https://github.com/matplotlib/matplotlib/blob/0d5a02a4e118eb098b78ea00039acd06310e54be/doc/devel/testing.rst. Is it known behaviour?dopplershift commentedon Mar 16, 2017
Are you aware of https://github.com/matplotlib/pytest-mpl ?
tacaswell commentedon Mar 16, 2017
@jnothman This will be in the 2.1 release so unless you have installed from source you will not have it.
pytest-mpl is probably a better option.
jnothman commentedon Mar 16, 2017
dopplershift commentedon Mar 16, 2017
@jnothman Have you seen the
remove_textoption forimage_comparison?phobson commentedon Mar 16, 2017
I think we can close this now. Is that the case?
QuLogic commentedon Mar 16, 2017
There are still items unchecked that need to be implemented or decided to ignore.
phobson commentedon Mar 16, 2017
Items I think we should ignore:
image_comparisondecorator. (this is an enhancement and clearly not a prerequisite)assert. (i think numpy.testing.assert_* should stay as-is)I'm -0 on using
pytest-mock(like all testing libraries, its docks assume I already know way more than I do)timhoffm commentedon May 30, 2019
I've marked
as done. I agree with @phobson that
numpy.testing.*functions should be kept. All other asserts are already written.Also checked
because there is no such file anymore.
anntzer commentedon May 30, 2019
I decided to strikeout the "use pytest-mock" line (agreeing with @phobson above); unittest.mock works just fine in the rare cases where we use it and bringing in a new dependency seems overkill (unless someone has a good use case for it in the test suite, in which case please speak up :)).
anntzer commentedon May 30, 2019
The "rewrite image_comparison (currently it slows down collection due to baseline image copying)" item seems not true anymore:
anntzer commentedon Jul 4, 2019
Technically there is one setup_method left in test_transforms.py, but in that specific case it doesn't seem worthwhile to remove it.
I'm thus declaring this issue closed :) Thanks to all for worked on it!