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

Cannot import xarray.tests due to use of pytest.config #1353

Closed
jjhelmus opened this issue Apr 5, 2017 · 6 comments
Closed

Cannot import xarray.tests due to use of pytest.config #1353

jjhelmus opened this issue Apr 5, 2017 · 6 comments

Comments

@jjhelmus
Copy link
Contributor

jjhelmus commented Apr 5, 2017

xarray.tests cannot be imported due to the use of pytest.config:

$ python -c "import xarray; print(xarray.__version__); import xarray.tests"
0.9.2-3-g9479038
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/jhelmus/devel/xarray/xarray/tests/__init__.py", line 118, in <module>
    not pytest.config.getoption("--run-flaky"),
AttributeError: module 'pytest' has no attribute 'config'

The use of pytest.config in the xarray/tests/__init__.py seem to have been introduced in #1336. From the discussion in pytest-dev/pytest#1688 it seems as if the use of pytest.config is discouraged.

@jjhelmus
Copy link
Contributor Author

jjhelmus commented Apr 5, 2017

pytest-dev/pytest#472 from BitBucket #472 seems to touch on this topic and references the note found at the end of the skip and xfail documentation:

You cannot use pytest.config.getvalue() in code imported before pytest’s argument parsing takes place.
For example, conftest.py files are imported before command line parsing and thus config.getvalue() will not execute correctly.

@shoyer
Copy link
Member

shoyer commented Apr 6, 2017

Hmm. This seems like an easy way to add a few options to running our test suite, but maybe there is a better way to do this? I guess we could hack in a fallback with hasattr() but that's pretty ugly.

Just out of curiosity, what reason did you have for importing xarray.tests?

@jjhelmus
Copy link
Contributor Author

jjhelmus commented Apr 6, 2017

Just out of curiosity, what reason did you have for importing xarray.tests?

xarray.tests is listed as a import test in the conda-forge xarray-feedstock and was failing when I was doing a build. I do not think that import line needs to be present, tests does not seem to be in the public API of xarray. I'd be in favor of removing that line and keeping the test suite setup as-is.

@shoyer
Copy link
Member

shoyer commented Apr 6, 2017

@jjhelmus Agreed! For testing public API, being able to import xarray and xarray.backends should be enough.

@shoyer
Copy link
Member

shoyer commented Apr 6, 2017

@jjhelmus
Copy link
Contributor Author

jjhelmus commented Apr 6, 2017

@shoyer Agreed, there is no need for xarray.tests to be importable. Closing this issue, thanks for the quick clarification.

@jjhelmus jjhelmus closed this as completed Apr 6, 2017
shoyer added a commit to conda-forge/xarray-feedstock that referenced this issue Apr 7, 2017
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

No branches or pull requests

2 participants