Skip to content

TST: skip a docstring-focused test when running in Python's optimized mode - #17478

Merged
mhvk merged 1 commit into
astropy:mainfrom
neutrinoceros:time/tst/adjust_test_for_optimized_mode
Nov 29, 2024
Merged

mhvk merged 1 commit into
astropy:mainfrom
neutrinoceros:time/tst/adjust_test_for_optimized_mode

Conversation

@neutrinoceros

Copy link
Copy Markdown
Contributor

Description

ref #17472

  • 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 29, 2024 11:32
@eerovaher

Copy link
Copy Markdown
Member

What is the purpose of the change here? If you are running the tests at an optimization level that discards docstrings then you are also running at an optimization level that discards assert statements, so trying to access the docstrings can't cause problems.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess this means the docstring creation itself was secure against optimization? That's nice to know!

@mhvk

mhvk commented Nov 29, 2024

Copy link
Copy Markdown
Contributor

@eerovaher - pytest assert are not affected by optimization - another bit of pytest magic - it rewrites the assert upon import of the test module - https://docs.pytest.org/en/stable/announce/release-2.1.0.html and https://docs.pytest.org/en/stable/how-to/assert.html#assert-details. (Discovered this in numpy/numpy#27868)

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

pytest assert are not affected by optimization

yes. I'm only addressing actual issues that I discover while actually running pytest with PYTHONOPTIMIZE=2, I'm not trying to guess what could be wrong.

@eerovaher

Copy link
Copy Markdown
Member

I can't run the tests with optimizations at all (with pytest 8.3.2)

$ PYTHONOPTIMIZE=1 pytest astropy/time/tests/test_sidereal.py
Traceback (most recent call last):
  ...
pytest.PytestConfigWarning: assertions not in test modules or plugins will be ignored because
assert statements are not executed by the underlying Python interpreter (are you using python -O?)

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

yes, one also needs to ignore this specific warning in pytest's configuration, which is annoying to do since you also have to know what builtin warning type PytestConfigWarning derives from.
I use this patch to run tests:

diff --git a/pyproject.toml b/pyproject.toml
index b2dea87895..985b3ef455 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -221,6 +221,7 @@ filterwarnings = [
     "error",
     "ignore:unclosed <socket:ResourceWarning",
     "ignore:unclosed <ssl.SSLSocket:ResourceWarning",
+    "ignore:assertions not in test modules or plugins will be ignored:UserWarning"
 ]
 doctest_norecursedirs = [
     "*/setup_package.py",

@mhvk
mhvk enabled auto-merge November 29, 2024 18:20
@mhvk
mhvk merged commit 8a3f8b9 into astropy:main Nov 29, 2024
@neutrinoceros
neutrinoceros deleted the time/tst/adjust_test_for_optimized_mode branch November 29, 2024 18:30
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