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

How to handle an optional package dependency in tests? #1710

Closed
rimey opened this issue Apr 8, 2016 · 4 comments
Closed

How to handle an optional package dependency in tests? #1710

rimey opened this issue Apr 8, 2016 · 4 comments
Assignees
Labels
packaging type: question Request for information or clarification. Not an issue.

Comments

@rimey
Copy link
Contributor

rimey commented Apr 8, 2016

#1691 adds gcloud.monitoring for accessing the Google Monitoring API. The initial focus is on querying of metric data.

The primary way in which users will want to get metric data is as a pandas DataFrame, and the Query class offers an as_dataframe() method for this purpose.

However, pandas is a large package with dependencies on yet other packages. I would not recommend gcloud-python taking a dependency on it.

We have taken the approach of importing pandas dynamically in as_dataframe(). The documentation explains that use of this method requires that you have pandas installed. This works perfectly.

Tests are still an issue, however. The unit tests for as_dataframe() naturally require pandas, which is not currently present in the test environment.

How should we handle this?

@rimey rimey added type: question Request for information or clarification. Not an issue. packaging build labels Apr 8, 2016
@rimey rimey mentioned this issue Apr 9, 2016
@tseaver
Copy link
Contributor

tseaver commented Apr 11, 2016

Maybe something like:

try:
     import pandas
except ImportError:
    HAVE_PANDAS = False
else:
    HAVE_PANDAS = True
from unittest2 import TestCase, skipUnless

class TestWithMaybePandas(TestCase):
    @skipUnless(HAVE_PANDAS, 'No pandas')
    def test_something_using_pandas(self):
          # whatever

Ideally you would add a tox environment (but maybe not one of the defaults) which added pandas to the dependencies, so that those tests could be exercised.

@rimey
Copy link
Contributor Author

rimey commented Apr 11, 2016

Done. PTAL.

What do we do about the test coverage analysis?

@dhermes
Copy link
Contributor

dhermes commented Apr 11, 2016

We may just have you add a no-cover pragma.

@rimey
Copy link
Contributor Author

rimey commented Apr 11, 2016

I added a py27-pandas tox environment, and I added no-cover pragmas.

Thank you, @tseaver and @dhermes, for the advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packaging type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants