Skip to content

Avoid import of classes from another test file - #15381

Merged
pllim merged 2 commits into
astropy:mainfrom
mhvk:wcs-tests-avoid-import-from-test-file
Sep 25, 2023
Merged

pllim merged 2 commits into
astropy:mainfrom
mhvk:wcs-tests-avoid-import-from-test-file

Conversation

@mhvk

@mhvk mhvk commented Sep 25, 2023

Copy link
Copy Markdown
Contributor

These classes add to the representations dict, and the cleanup is messy. Better just to redefine the two representations that are needed.

Fixes the failures noted by @pllim in #14820 (comment)

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@mhvk mhvk added testing wcs Affects-dev PRs and issues that do not impact an existing Astropy release no-changelog-entry-needed Extra CI Run cron CI as part of PR labels Sep 25, 2023
@mhvk mhvk added this to the v6.0 milestone Sep 25, 2023
@mhvk
mhvk requested a review from mcara as a code owner September 25, 2023 17:26
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@pllim

pllim commented Sep 25, 2023

Copy link
Copy Markdown
Member

Some of the failures are unrelated but this looks related:

astropy.utils.exceptions.DuplicateRepresentationWarning: Representation "iaumars2000geodetic" already defined

@mhvk

mhvk commented Sep 25, 2023

Copy link
Copy Markdown
Contributor Author

Darn. So, somehow the setup_function/teardown_function doesn't work. I'll investigate.

@mhvk
mhvk force-pushed the wcs-tests-avoid-import-from-test-file branch from e53383e to 2f5bb61 Compare September 25, 2023 19:28
@mhvk

mhvk commented Sep 25, 2023

Copy link
Copy Markdown
Contributor Author

OK, found the problem. Tests pass locally at least...


# Preserve the original REPRESENTATION_CLASSES dict so that importing
# the test file doesn't add a persistent test subclass (CustomGeodetic, etc.)
REPRESENTATION_CLASSES_ORIG = deepcopy(REPRESENTATION_CLASSES)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be in setup_module to be consistent with teardown?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I started that, but then I still need to define global variables, no? In the end, it seemed an unnecessary complication. But maybe I was overcomplicating things - how should this be done?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, good point. I guess this is fine since pyinstaller is happy. Thanks for the clarification!

@pllim

pllim commented Sep 25, 2023

Copy link
Copy Markdown
Member

numpy dev and exotic arch failures should be unrelated though I expect the pyinstaller job to be green.

@mhvk

mhvk commented Sep 25, 2023

Copy link
Copy Markdown
Contributor Author

numpy dev and exotic arch failures should be unrelated though I expect the pyinstaller job to be green.

It seems to have worked...

@pllim

pllim commented Sep 25, 2023

Copy link
Copy Markdown
Member

Do you still need this import?

from astropy.coordinates.tests.test_representation import (  # noqa: F401
    setup_function,
    teardown_function,
)

These classes add to the representations dict, and the cleanup is
messy.  Better just to redefine the two representations that are
needed.  Similarly, importing setup_function and teardown_function is
risky; here, actually teardown_module was needed.
@mhvk
mhvk force-pushed the wcs-tests-avoid-import-from-test-file branch from 2f5bb61 to 052d960 Compare September 25, 2023 20:27
@mhvk

mhvk commented Sep 25, 2023

Copy link
Copy Markdown
Contributor Author

Oops, thanks for catching that... that import should go! Removed.

@pllim

pllim commented Sep 25, 2023

Copy link
Copy Markdown
Member

Unfortunately, I don't think your patch work for "double run"?

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the failure in Python 3.10 in Parallel with all optional dependencies is related.

Here, use setup_class and teardown_class instead of teardown_module.
@mhvk

mhvk commented Sep 25, 2023

Copy link
Copy Markdown
Contributor Author

Darn. Cannot quite reproduce the failure locally, so am trying something fairly desparate -- put all the tests in a class and use setup_class and teardown_class -- I do like that format better anyway, but don't know if it will actually help. Sigh.

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM now. Thanks!

@pllim
pllim merged commit 169139c into astropy:main Sep 25, 2023
@mhvk
mhvk deleted the wcs-tests-avoid-import-from-test-file branch September 26, 2023 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Affects-dev PRs and issues that do not impact an existing Astropy release Extra CI Run cron CI as part of PR no-changelog-entry-needed testing wcs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants