Skip to content

TST: fix a test for compatibility with Python 3.13#16659

Merged
nden merged 1 commit intoastropy:mainfrom
neutrinoceros:modeling/test/bug/python313_compat
Aug 15, 2024
Merged

TST: fix a test for compatibility with Python 3.13#16659
nden merged 1 commit intoastropy:mainfrom
neutrinoceros:modeling/test/bug/python313_compat

Conversation

@neutrinoceros
Copy link
Contributor

@neutrinoceros neutrinoceros commented Jul 2, 2024

Description

This pull request is to address the only known incompatibility with Python 3.13 in our test suite (see #16600)
xref upstream issue: python/cpython#121257 (in particular python/cpython#121257 (comment))

The problematic (long) test was introduced in a large PR (#12232) so I can only guess that mocking was used only as a convenience and expanding the assertion is really equivalent (just more verbose and incidentally, more reliable).

  • 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.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 2, 2024

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?
  • 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.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 2, 2024

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

# model is not None
param._model_required = False
model = mk.MagicMock()
with mk.patch.object(functools, "partial", autospec=True) as mkPartial:
Copy link
Member

Choose a reason for hiding this comment

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

I don't grok what the original code was trying to do, being unfamiliar with so deep within modeling internals. This was added by @WilliamJamieson in #12232 so hopefully he can review? 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Would it be easier to use pytest.monkeypatch instead of unittest.mock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is simply not safe to patch this function at all (see linked issue at CPython).
My understanding is that MagicMock was merely a convenient way to implement comparison in very few lines.

@pllim pllim added this to the v6.1.2 milestone Jul 2, 2024
@neutrinoceros neutrinoceros force-pushed the modeling/test/bug/python313_compat branch 2 times, most recently from 942538e to e1e2f8f Compare July 14, 2024 13:41
@neutrinoceros
Copy link
Contributor Author

image test failure is clearly not correlated, and addressed in #16722

@neutrinoceros neutrinoceros force-pushed the modeling/test/bug/python313_compat branch from e1e2f8f to c2800e2 Compare July 22, 2024 14:31
@neutrinoceros
Copy link
Contributor Author

rebased to check Python 3.13.0b4

@astrofrog astrofrog modified the milestones: v6.1.2, v6.1.3 Jul 25, 2024
@neutrinoceros neutrinoceros force-pushed the modeling/test/bug/python313_compat branch from c2800e2 to 9fd25c0 Compare August 14, 2024 16:57
@neutrinoceros
Copy link
Contributor Author

This is now based on top of #16596 so that PR can be merged first. Switching this one to draft for now.

@neutrinoceros neutrinoceros marked this pull request as draft August 14, 2024 16:58
@neutrinoceros neutrinoceros force-pushed the modeling/test/bug/python313_compat branch from 9fd25c0 to cce2172 Compare August 14, 2024 17:02
@pllim
Copy link
Member

pllim commented Aug 14, 2024

If you rebase again, only the modeling test should be in diff here. And please remember to remove the xfail. Thanks!

@neutrinoceros neutrinoceros force-pushed the modeling/test/bug/python313_compat branch from cce2172 to cbff431 Compare August 15, 2024 06:15
@neutrinoceros
Copy link
Contributor Author

whoops, I thought I did already, but I clearly made a mistake in my previous rebase. It's fixed now, thanks for catching this !

@neutrinoceros neutrinoceros force-pushed the modeling/test/bug/python313_compat branch from cbff431 to d6a9ac0 Compare August 15, 2024 06:16
@neutrinoceros neutrinoceros marked this pull request as ready for review August 15, 2024 06:44
Copy link
Contributor

@nden nden left a comment

Choose a reason for hiding this comment

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

This looks like a better solution.

@nden nden merged commit 2617fde into astropy:main Aug 15, 2024
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Aug 15, 2024
@neutrinoceros neutrinoceros deleted the modeling/test/bug/python313_compat branch August 15, 2024 21:04
pllim added a commit that referenced this pull request Aug 16, 2024
…659-on-v6.1.x

Backport PR #16659 on branch v6.1.x (TST: fix a test for compatibility with Python 3.13)
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.

5 participants