◐ Shell
clean mode source ↗

gh-92886: Replace assertion statements in `handlers.BaseHandler` to support running with optimizations (`-O`) by jackh-ncl · Pull Request #93231 · python/cpython

Replace assert statements with raise AssertionError() so that behaviour is maintained and test_wsgiref.py tests pass while running with optimizations (-O).

$ ./python.exe -Om unittest test.test_wsgiref

.......................FFF...........
======================================================================
FAIL: test_status_validation_errors (test.test_wsgiref.IntegrationTests.test_status_validation_errors) (status='200')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/.../dev/cpython/Lib/test/test_wsgiref.py", line 177, in test_status_validation_errors
    self.assertTrue(out.endswith(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true

======================================================================
FAIL: test_status_validation_errors (test.test_wsgiref.IntegrationTests.test_status_validation_errors) (status='20X OK')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/.../dev/cpython/Lib/test/test_wsgiref.py", line 177, in test_status_validation_errors
    self.assertTrue(out.endswith(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true

======================================================================
FAIL: test_status_validation_errors (test.test_wsgiref.IntegrationTests.test_status_validation_errors) (status='200OK')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/.../dev/cpython/Lib/test/test_wsgiref.py", line 177, in test_status_validation_errors
    self.assertTrue(out.endswith(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true

----------------------------------------------------------------------
Ran 35 tests in 0.039s

FAILED (failures=3)
$ ./python.exe -Om unittest test.test_wsgiref

...................................
----------------------------------------------------------------------
Ran 35 tests in 0.030s

OK