Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pytest.importorskip in tests #492

Merged
merged 3 commits into from
Nov 9, 2019

Conversation

jrbourbeau
Copy link
Member

@jrbourbeau jrbourbeau commented Oct 25, 2019

This PR replaces (almost all) occurrences of try/except blocks to determine if a library is available with pytest.importorskip. I wasn't able to replace this LZMA import

try:
from numcodecs import LZMA
except ImportError: # pragma: no cover
LZMA = None

because it's used in other conditional statements in test_core.py.

Also added a skip_test_env_var utility function to zarr/tests/util.py to replace some of the boilerplate code related to skipping tests based on environment variables (e.g. ZARR_TEST_ABS)

Closes #229

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • Docs build locally (e.g., run tox -e docs)
  • AppVeyor and Travis CI passes
  • Test coverage is 100% (Coveralls passes)

def skip_test_env_var(name):
""" Checks for environment variables indicating whether tests requiring services should be run
"""
value = os.environ.get(name, '0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle empty strings? If so, this might help.

Suggested change
value = os.environ.get(name, '0')
value = os.environ.get(name, '') or '0'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure. Is an empty string a common pattern for disabling things with an env var? If so, then it's probably worth supporting here. No strong opinion from me one way or the other

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more so that it is not a common pattern for enabling things. So the concern would be someone accidentally enabling these.

That said, let's leave it since it was already this way and we can follow-up in another issue/PR.

@jakirkham
Copy link
Member

jakirkham commented Nov 7, 2019

Thanks for working on this James! This looks much better.

As CIs install some sets of these, we may want to set the environment variables on CI. Apologies. Missed that we already do. 😅

@jakirkham jakirkham merged commit 59df302 into zarr-developers:master Nov 9, 2019
@jakirkham
Copy link
Member

Thanks @jrbourbeau! 😄

@jrbourbeau jrbourbeau deleted the importorskip branch November 9, 2019 01:57
@Carreau Carreau added this to the v2.4 milestone Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider using pytest.importorskip
3 participants