Consider using pytest.importorskip('dependency') in testing
See original GitHub issueThere is a helper function in pytest importorskip
that might help clean up testing code. This would generally replace something like @skipif('not HAS_DEPENDENCY')
with a line inside the test function / method dependency = pytest.importorskip('dependency')
.
I’m not completely sure this is an overall win, but we should think about this as a new standard idiom.
Issue Analytics
- State:
- Created 7 years ago
- Comments:20 (20 by maintainers)
Top Results From Across the Web
How to use skip and xfail to deal with tests that cannot succeed
Skipping on a missing import dependency¶. You can skip tests on a missing import by using pytest.importorskip at module level, within a test,...
Read more >pytest-dependency 0.5.1 documentation - Read the Docs
Consider the following example test module: import pytest @pytest.mark.dependency() ... All the tests are decorated with pytest.mark.dependency() .
Read more >pytest Documentation - Read the Docs
Skipping on a missing import dependency. You can skip tests on a missing import by using pytest.importorskip at module level, within a test, ......
Read more >[TIP] Add pytest requires_dependency decorator in addition to ...
[TIP] Add pytest requires_dependency decorator in addition to importorskip? ... have a lot of tests (using pytest) that require optional dependencies.
Read more >Reference — pytest documentation
It will also override any fixture-function defined scope, allowing to set a dynamic scope using test context or configuration. pytest.mark.skip¶. Tutorial: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve written to the testing-in-python list about this, the thread starts here: http://lists.idyll.org/pipermail/testing-in-python/2016-December/006962.html
I’ll post here again in a few days with a summary / recommendation on how to proceed.
Still, opinions welcome of course here in the meantime what you’d prefer to have for Astropy core!
“You can use the following import helper at module level or within a test or test setup function:”