<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">Astropy and other packages have a lot of tests (using pytest) that require optional dependencies.</div><div class=""><br class=""></div><div class="">So far the approach for marking such tests has been this:</div><div class=""><a href="http://astropy.readthedocs.io/en/latest/development/testguide.html#tests-requiring-optional-dependencies" class="">http://astropy.readthedocs.io/en/latest/development/testguide.html#tests-requiring-optional-dependencies</a></div><div class="">which has lead to a lot of boilerplate try-except import code at the top of test files.</div><div class=""><br class=""></div><div class="">We’re now discussing how to simplify this and would like your input before taking a decision.</div><div class="">See&nbsp;<a href="https://github.com/astropy/astropy/issues/5543" class="">https://github.com/astropy/astropy/issues/5543</a></div><div class=""><br class=""></div><div class="">To summarise, one proposal is to use pytest.importorskip and put those statement as first line in the test functions.</div><div class=""><a href="http://doc.pytest.org/en/latest/skipping.html#skipping-on-a-missing-import-dependency" class="">http://doc.pytest.org/en/latest/skipping.html#skipping-on-a-missing-import-dependency</a></div><div class=""><br class=""></div><div class="">An alternative proposal is to define a decorator that wraps “pytest.mark.skipif”,</div><div class="">see&nbsp;<a href="https://github.com/astropy/astropy/issues/5543#issuecomment-265434710" class="">https://github.com/astropy/astropy/issues/5543#issuecomment-265434710</a>&nbsp;and the following comments.</div><div class=""><br class=""></div><div class="">It was pointed out that at least one other project came up independently with a similar solution of wrapping “pytest.mark.skipif”:</div><div class=""><a href="https://github.com/glue-viz/glue/blob/master/glue/tests/helpers.py#L14" class="">https://github.com/glue-viz/glue/blob/master/glue/tests/helpers.py#L14</a></div><div class=""><br class=""></div><div class="">In my opinion a declarative syntax with a decorator line before the function is more obvious / nicer than putting a&nbsp;pytest.importorskip inside the test function.</div><div class=""><br class=""></div><div class="">So here’s my concrete questions:</div><div class=""><br class=""></div><div class="">Are there any real pros and cons for the two options? Or are both equally powerful and it’s a matter of taste?</div><div class=""><br class=""></div><div class="">Do you think such a decorator would be appropriate for a pytest plugin?</div><div class="">Or even to be proposed as a convenience for pytest core?</div><div class="">Or would you just recommend we implement what we want in our own `utils.py` instead of trying to generalise a solution for this?</div><div class=""><br class=""></div><div class="">Thank you in advance!</div><div class=""><br class=""></div><div class="">Christoph</div></body></html>