question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Skip tests relying on absent optional/external libaries

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hectormzcommented, Apr 1, 2020

Yes it did (from my perspective). You can close this now if it works for you.

1reaction
hectormzcommented, Mar 8, 2020

@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 imports

import torch
import pyro
from pyro.infer import Predictive

can be replaced with

torch = pytest.importorskip("torch")
pyro = pytest.importorskip("pyro")
Predictive = pytest.importorskip("pyro.infer.Predictive")

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Skip tests for optional dependencies if they are not installed
I just tried to run the test suite and had some failures because I don't have some of the Chemistry packages installed. I...
Read more >
How to use skip and xfail to deal with tests that cannot succeed
You can skip tests on a missing import by using pytest.importorskip at module level, within a test, or test setup function. docutils =...
Read more >
Separating unit tests and integration tests in Go - Stack Overflow
I have a mix of unit tests (which do not rely on any external resources and thus run really fast) and integration tests...
Read more >
Testing in Java & JVM projects - Gradle User Manual
Testing on the JVM is a rich subject matter. There are many different testing libraries and frameworks, as well as many different types...
Read more >
A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Unit tests are designed to test the behavior of specific classes or methods without relying on the behavior of their dependencies. Since we're...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found