bpo-46111: Fix unittest tests in optimized mode (GH-30163)

(cherry picked from commit 95a922b3bb3af247ec141d73fcdfbf68bb1d32a5)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
3 files changed