Skip to content

TST: simplify a warning-capturing test#18954

Merged
neutrinoceros merged 1 commit intoastropy:mainfrom
neutrinoceros:tst/refactor-table-test-warning-capture
Nov 21, 2025
Merged

TST: simplify a warning-capturing test#18954
neutrinoceros merged 1 commit intoastropy:mainfrom
neutrinoceros:tst/refactor-table-test-warning-capture

Conversation

@neutrinoceros
Copy link
Copy Markdown
Contributor

Description

I stumbled upon a failure mode of this test case while working on #18782, and it took me longer than it should have to figure out what was happening. This should be a simple refactor, but a QoL improvement for debugging.

  • 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
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?
  • 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
Copy Markdown
Contributor

👋 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?

@neutrinoceros neutrinoceros marked this pull request as ready for review November 17, 2025 11:26
self._from_dataframe(
df, backend, use_legacy_pandas_api, units={"x": u.m, "t": u.s, "y": u.m}
)
assert len(record) == 1
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.

You might still want to keep the len check, to catch multiple same warnings being emitted when it is not supposed to?

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.

A pytest.raise context scoped with a sufficiently restrictive match argument, should already achieve the desired goal. The issue I encountered with this test was specifically that another warning is emitted from a transitive dependency (with sufficiently old versions of everything), and while I still need to handle that other warning (left as a follow up), it would be pretty fragile to modify the expected number of warnings dynamically, so I wanted to first make this incremental improvement

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.

match does not guard against duplicate warnings. I think removing len check here is not a one-to-one code replacement but I'll defer to @taldcroft .

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.

The code in question can only raise one matching warning, so I'm OK with this.

self._from_dataframe(
df, backend, use_legacy_pandas_api, units={"x": u.m, "t": u.s, "y": u.m}
)
assert len(record) == 1
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.

The code in question can only raise one matching warning, so I'm OK with this.

@neutrinoceros neutrinoceros merged commit 6391116 into astropy:main Nov 21, 2025
46 of 48 checks passed
@neutrinoceros neutrinoceros deleted the tst/refactor-table-test-warning-capture branch November 21, 2025 14:31
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