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. |
|
|
||
| # 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.
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.
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.
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.
Very cool! Thanks! I'll read those more carefully to see what they're doing there 😁
Please squash