Skip tests relying on absent optional/external libaries
See original GitHub issueDescribe the issue
Arviz
is meant to use/interact with external libraries that are optional, found in requirements-external.txt
, requirements-optional.txt
, with tests found in /tests/external-tests/
. I’d propose making these tests optional when the other libraries aren’t installed, so someone not touching those areas could run tests locally without installing all the packages.
Suggested change
In pyjanitor
we support the use of some optional, external libraries and skip tests if the libraries can’t be loaded.
I propose modifying the test files to something like this:
try:
import emcee
except ImportError:
emcee= None
@pytest.mark.skipif(emcee is None, reason="emcee tests only required for CI")
def some_emcee_test():
CI should still run as is, but it’d be a bit easier for new people to get involved and test without the external libraries.
One issue with this is at least once instance with this (for pyro
at least) is when a skipif
decorator is also checking for pyro.version
which will cause an error when it is None
etc.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Yes it did (from my perspective). You can close this now if it works for you.
@OriolAbril I wasn’t aware of that skip, is that built into
pytest
? nice!I was looking into the
pytest.mark.skipif
documentation and found there is an option to skip tests based on missing a dependency:pytest.importorskip
Assuming that our tests for external libraries are in separate files, this might work well. In
test_data_pyro.py
, the importscan be replaced with
I believe the whole file will be skipped if one of those imports fails. No other decorators need to be added to the classes/tests. I think this minimal code change is ideal, as long as the changes to imports are clear/commented well, and
pylint
is silenced about no longer seeing these imports as imports.