-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MNT: Merge locally defined test marks #23045
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
Depending on the merge order of this and #23033 I will update the one that is not merged first. |
lib/matplotlib/testing/decorators.py
Outdated
needs_ghostscript = pytest.mark.skipif( | ||
"eps" not in matplotlib.testing.compare.converter, | ||
reason="This test needs a ghostscript installation") |
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.
Rather than a decorator, should these be turned into a "marker"? Then you'd decorate the tests with:
@pytest.mark.needs_lualatex
and avoid the decorator imports.
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.
How exactly would that work? You'd evaluate whether gostscript is present at test startup and then modify the marker selection? I don't know how to do that but I guess that's possible. However, importing the decorator seems much simpler.
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 wasn't sure how easy it would be myself, just figured it would be worth the thought :) I think we could intercept the setup of the test and say something like:
if needs_ghostscript in item.markers and "eps" not in matplotlib.testing.compare.converter:
pytest.skip(reason=...)
https://docs.pytest.org/en/6.2.x/example/markers.html#marking-platform-specific-tests-with-pytest
I agree though, that might be more than necessary here.
lib/matplotlib/testing/decorators.py
Outdated
needs_ghostscript = pytest.mark.skipif( | ||
"eps" not in matplotlib.testing.compare.converter, | ||
reason="This test needs a ghostscript installation") |
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 wasn't sure how easy it would be myself, just figured it would be worth the thought :) I think we could intercept the setup of the test and say something like:
if needs_ghostscript in item.markers and "eps" not in matplotlib.testing.compare.converter:
pytest.skip(reason=...)
https://docs.pytest.org/en/6.2.x/example/markers.html#marking-platform-specific-tests-with-pytest
I agree though, that might be more than necessary here.
I think the doc failure is relevant here?
|
I guess that there are a few solutions to the doc-build problem:
Any preference? "Problem" is: https://matplotlib.org/stable/api/testing_api.html |
I remember trying to do this a while ago, hitting this docs problem and then giving up on the effort :-p I'm between 1 and "just accept the duplication". |
I think you can actually define these using |
That sounds brittle and works until it does not in confusing ways.... Given that we require scipy, a pretty complete latex, and graphviz to build the docs, adding |
Why? This is explicitly documented as working: https://docs.pytest.org/en/6.2.x/unittest.html |
Fair, I still have concerns, but if it works, lets go with that plan.
Fair, but the point still stands for the other heavy dependencies and one more (pure-python) dependency is not too onerous. |
Note that this also means making matplotlib.testing.decorators not importable if pytest is not present (do you want to wrap the import in a try... except to reraise a more explicit exception?). Nothing undoable (and I doubt anyone is really importing that module for anything but doing pytest-related things), but I always feel like this slightly muddies the picture. |
-1 on adding a dependency on pytest. -0.3 on using unittest. That's a working but non-standard solution. If we do that, it needs explanation. Can we put the decorators in |
I wonder how this meshes with #14455? Or is that one now outdated? |
I can try and deprecate I'll find a new place for the remaining decorators. |
Thinking again, it would be ok to have the decorators in testing if that does not introduce an import-time dependency on pytest. So some variant of |
170db62
to
e80df49
Compare
cc9fbbc
to
8bd907f
Compare
It struck me that these are actually not decorators, but marks. So makes sense to add a file I also deprecated |
lib/matplotlib/testing/marks.py
Outdated
return True | ||
|
||
|
||
needs_ghostscript = pytest.mark.skipif( |
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.
By putting them here, we're technically making them public: matplotlib.testing.marks.needs_ghostscript
.
While I'm not sure whether testing
itself should be public. Let's not add to it. Either _marks.py
or prefix all the markers. I'd go with the first, similar to _api
.
Oh, and pytest calls these "markers". so, _markers.py
it is.
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.
Not critical here, but I still don't think these are technically markers because they aren't in the pytest.mark
namespace, which means someone can't skip these from the command line with something like: pytest -m "not latex"
.
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 was also thinking about that after reading up a bit further. On the other hand, I do not think you can do pytest -m "not skipif"
either? So marker seems to have a rather wide interpretation.
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.
Turns out you can actually do that, pytest -m skipif
.
Should I rename it to _decorators.py
then?
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 wouldn't. I think it would actually be more confusing to have both a _decorators.py
and decorators.py
file in the same 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.
I guess one can add them as proper markers, but I had a quick look and it seemed to require quite a bit more effort than possibly worth it. As far as I can tell one would need to create a proper conftest.py
with functions checking the markers and so on, not simply "inserting" a named marker derived from another marker. But I could have been bad at searching.
(Which is basically what you stated in an earlier comment.)
needs_ghostscript = pytest.mark.skipif( | ||
"eps" not in matplotlib.testing.compare.converter, | ||
reason="This test needs a ghostscript installation") | ||
needs_lualatex = pytest.mark.skipif( |
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.
@oscargus Sorry I missed this before merging, but these names seem not so optimal now? needs_{lua,pdf,xe}latex now check both for the tex engine, and for the presence of pgf (this was less of an issue when the marks were local to test_backend_pgf. Perhaps rename them to needs_{lua,pdf,xe}tex_pgf
? (Or just move them back to being local to the pgf backend test suite.)
PR Summary
Identical test marks were defined in multiple files. This moves them to
testing.marks
(for consistency, even if they were only defined in a single file).Also deprecates
matplotlib.checkdep_usetex
.Closes #14455
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).