August 2018
Beginner
160 pages
4h 8m
English
It is common for libraries to have tests that depend on a certain library being installed. For example, pytest's own test suite has some tests for numpy arrays, which should be skipped if numpy is not installed.
One way to handle this would be to manually try to import the library and skip the test if it is not present:
def test_tracers_as_arrays_manual(): try: import numpy except ImportError: pytest.skip("requires numpy") ...
This can get old quickly, so for this reason, pytest provides the handy pytest.importorskip function:
def test_tracers_as_arrays(): numpy = pytest.importorskip("numpy") ...
pytest.importorskip will import the module and return the module object, or skip the test entirely if the module could not be ...
Read now
Unlock full access