-
Notifications
You must be signed in to change notification settings - Fork 25
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
also run dataclasses test with optimizations enabled #275
Conversation
8585b8e
to
0168a77
Compare
0cc788a
to
2fe0a10
Compare
With these changes, we perhaps won't need a way to provide a |
By the way, the |
That's weird. I thought Python 3.13 was available on Github. Any idea why it's not picked up? |
Yeah, it is available. But for some reason Edit: Perhaps they can't decide whether to use freethreading or not? 🤣 |
Nah, they'll update it soon enough. Don't have time to track Github's Python version shenanigans in detail. |
@@ -97,6 +97,10 @@ jobs: | |||
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/build-and-test-py-project.sh | |||
. ./build-and-test-py-project.sh | |||
|
|||
# Also run with optimizations turned on, since opt_frozen_dataclass | |||
# depends on the __debug__ setting. | |||
python -O -m pytest pytools/test/test_dataclasses.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, but how does this work? I thought -O
disabled assertions, but pytest
does some assertion hackery to make the tests fail and whatnot, so combining them seems very odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Great question. I had not thought about this. It used to be the case that pytest got upset when you ran it with python -O
, but that's (clearly!) no longer the case. So something else must be happening. A litte bit of digging turns up that pytest rewrites the AST to swap out assert
statements for something entirely different, which, IIUC, makes it OK for pytest to run with python -O
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how pytest re-enables assertions when running with -O, but I think they rewrite them to provide more information? (see e.g. https://github.com/pytest-dev/pytest/blob/9d4f36d87dae9a968fb527e2cb87e8a507b0beb3/src/_pytest/assertion/rewrite.py)
They seem to work fine as long as they occur in the test module. See this warning from CI:
=============================== warnings summary ===============================
.env/lib/python3.12/site-packages/_pytest/config/__init__.py:1278
/home/runner/work/pytools/pytools/.env/lib/python3.12/site-packages/_pytest/config/__init__.py:1278: 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?)
self._warn_about_missing_assertion(mode)
We set -O not because of assertions, but to modify the value of __debug__
, which is what opt_frozen_dataclass
looks at.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! Thanks! I'll read those more carefully to see what they're doing there 😁
Please squash