[TIP] Add pytest requires_dependency decorator in addition to importorskip?
nicoddemus at gmail.com
Wed Dec 7 13:23:46 PST 2016
On Wed, Dec 7, 2016 at 11:51 AM Christoph Deil deil.christoph at googlemail.com
Are there any real pros and cons for the two options? Or are both equally
> powerful and it’s a matter of taste?
IMHO it seems to be a matter of taste. The requires_dependency function
still requires you to explicitly import the module inside the test file to
obtain the module object:
from gammapy.utils.testing import requires_dependency
Compared with pytest.importorskip:
scipy = pytest.importorskip('scipy')
So I think requires_dependency has the following cons:
- It might be more explicit, since pytest.importorskip might be used
deep inside the test function and easy to miss, while the decorator stands
- It is more friendly to IDEs like PyCharm/PyDev, with code-completion,
The only cons I can think of is that it requires one extra line and the
extra import (since it is common for tests to import pytest for other
reasons as well).
Do you think such a decorator would be appropriate for a pytest plugin?
If others find it useful, I don’t see why not. :)
Or even to be proposed as a convenience for pytest core?
I personally would be -0 on this because I feel it seems too similar to
using pytest.importorskip method so I would avoid having two ways of doing
the same thing. On the other hand, the implementation would be really
simple so it wouldn’t be a maintenance burden if others really like it.
Or would you just recommend we implement what we want in our own `utils.py`
> instead of trying to generalise a solution for this?
I think it is really commendable of you to try to provide a general
solution to the community, so please don’t get discouraged by my -0. And
since the implementation is simple and cookiecutter-pytest-plugin
<https://github.com/pytest-dev/cookiecutter-pytest-plugin> makes creating
plugins a snap, you should definitely go with it if you really prefer the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python