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

move conftest contents to asdf/conftest #1645

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

braingram
Copy link
Contributor

@braingram braingram commented Sep 13, 2023

As mentioned here: #1614 (comment)
asdf tests for the installed package (for example 2.15.1 on pypi) do not run when run with pytest --pyargs asdf with the following error:

E   AttributeError: 'Namespace' object has no attribute 'jsonschema'

This appears to be due to change in #1591 which register a jsonschema config for pytest in a conftest.py that is not included with the installed package.
This PR moves the contents of conftest.py (which is not included in the installed package) to asdf/conftest.py (which is included in the installed package).

I tested this locally and it appears to fix the issue. Given the note below about the CI failing to catch this (even though it looks like it should) makes me not trust the CI as a judge of this PR.

@zacharyburnett any clue why the package CI that is run on PRs didn't catch this:

package:
needs: [core, asdf-schemas]
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
with:
upload_to_pypi: false
upload_to_anaconda: false
test_extras: tests
test_command: pytest --pyargs asdf

It appears to build the packge, install it, cd to a temp directory and run the same command as above:
https://github.com/asdf-format/asdf/actions/runs/6146839026/job/16677609197#step:7:1246
Perhaps it's because it's using a sdist instead of a wheel? EDIT: tests also appear to pass with the wheel: https://github.com/asdf-format/asdf/actions/runs/6146839026/job/16677609197#step:7:4231

@zacharyburnett
Copy link
Member

zacharyburnett commented Sep 13, 2023

@zacharyburnett any clue why the package CI that is run on PRs didn't catch this:

yes I was wondering why the pyargs test didn't pick it up; perhaps there is still a residual install-from-source present in the OpenAstronomy workflow at the point when it gets to executing the test-command?

@braingram
Copy link
Contributor Author

@zacharyburnett any clue why the package CI that is run on PRs didn't catch this:

yes I was wondering why the pyargs test didn't pick it up; perhaps there is still a residual install-from-source present in the OpenAstronomy workflow at the point when it gets to executing the test-command?

Thanks! That sounds believable. I tried looking through the various action and log files and didn't see anything obvious. Perhaps we should be installing the package from pip and running tests as part of maybe the weekly cron. Does that seem worthwhile?

@zacharyburnett
Copy link
Member

zacharyburnett commented Sep 14, 2023

Thanks! That sounds believable. I tried looking through the various action and log files and didn't see anything obvious. Perhaps we should be installing the package from pip and running tests as part of maybe the weekly cron. Does that seem worthwhile?

We can try making a -pyargs Tox env and overriding the install method as well as the test command; that may be more effective than using the test-command input to the OpenAstronomy action



@pytest.fixture(scope="session", autouse=True)
def _temp_cwd(tmpdir_factory):
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what's going on, or if it really matters, but tese changes are causing some test failures when asdf is installed in editable mode. For example pytest fails on a code block in the docs/asdf/config.rst file:

$ pytest docs/asdf/config.rst
================================================================================================ test session starts =================================================================================================
platform darwin -- Python 3.10.8, pytest-7.2.0, pluggy-1.0.0
Matplotlib: 3.6.2
Freetype: 2.6.1
rootdir: /Users/eslavich/repos/asdf, configfile: pyproject.toml
plugins: remotedata-0.4.0, hypothesis-6.70.0, mock-3.10.0, filter-subpackage-0.1.2, requests-mock-1.10.0, mpl-0.16.1, astropy-header-0.2.2, doctestplus-0.12.1, astropy-0.10.0, cov-4.0.0, ci-watson-0.6.1, openfiles-0.5.0, anyio-3.6.2, asdf-3.0.0.dev600+g02752c84, arraydiff-0.5.0, httpserver-1.0.6
collected 1 item

docs/asdf/config.rst F                                                                                                                                                                                         [100%]

====================================================================================================== FAILURES ======================================================================================================
________________________________________________________________________________________________ [doctest] config.rst ________________________________________________________________________________________________
027 --------------------------------
028
029 There are two methods available that give access to an `AsdfConfig` instance:
030 `~asdf.get_config` and `~asdf.config_context`.  The former simply returns
031 the currently active config:
032
033 .. code-block:: pycon
034
035     >>> import asdf
036     >>> asdf.get_config()
UNEXPECTED EXCEPTION: AttributeError("module 'asdf' has no attribute 'get_config'")
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/asdf/lib/python3.10/doctest.py", line 1350, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest config.rst[3]>", line 1, in <module>
AttributeError: module 'asdf' has no attribute 'get_config'
/Users/eslavich/repos/asdf/docs/asdf/config.rst:36: UnexpectedException
============================================================================================== short test summary info ===============================================================================================
FAILED docs/asdf/config.rst::config.rst
================================================================================================= 1 failed in 0.07s ==================================================================================================

but when I restore the conftest.py file it works:

$ git checkout main -- conftest.py
$ pytest docs/asdf/config.rst
================================================================================================ test session starts =================================================================================================
platform darwin -- Python 3.10.8, pytest-7.2.0, pluggy-1.0.0
Matplotlib: 3.6.2
Freetype: 2.6.1
rootdir: /Users/eslavich/repos/asdf, configfile: pyproject.toml
plugins: remotedata-0.4.0, hypothesis-6.70.0, mock-3.10.0, filter-subpackage-0.1.2, requests-mock-1.10.0, mpl-0.16.1, astropy-header-0.2.2, doctestplus-0.12.1, astropy-0.10.0, cov-4.0.0, ci-watson-0.6.1, openfiles-0.5.0, anyio-3.6.2, asdf-3.0.0.dev600+g02752c84, arraydiff-0.5.0, httpserver-1.0.6
collected 1 item

docs/asdf/config.rst .                                                                                                                                                                                         [100%]

================================================================================================= 1 passed in 2.09s ==================================================================================================

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Puzzling... I'm not sure what's happening there either. I tried testing this locally and that tests (and all other tests) pass without issue for an editable install (installed with pip install -e .).

Did the environment previously have asdf installed? Based on the error you saw AttributeError: module 'asdf' has no attribute 'get_config' it might be that the pytest plugin of the old installation left behind a 'ghost' namespace (see: #790) but I'm not sure how restoring the conftest.py would fix this :-/

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, oops, good call -- I tried again with a fresh environment and didn't run into the same problem.

@braingram braingram added this to the 3.0.0 milestone Sep 18, 2023
Copy link
Contributor

@eslavich eslavich left a comment

Choose a reason for hiding this comment

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

LGTM

@braingram braingram merged commit ea65975 into asdf-format:main Sep 29, 2023
32 checks passed
@braingram braingram deleted the fix_package_tests branch September 29, 2023 11:55
braingram added a commit to braingram/asdf that referenced this pull request Sep 29, 2023
@braingram
Copy link
Contributor Author

braingram commented Sep 29, 2023

@zacharyburnett this fix is now in the released 2.15.2 version. Testing with pytest --pyargs asdf on a pip installed asdf works (with all tests passed)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants