Assert that works in release mode. Accepts callable msg to allow deferring evaluation until failure. The Python built-in ``assert`` does not work when executing code in optimized mode (the ``-O`` flag) - no byte-code is generated for it. For documentation on usage, refer to th
(val, msg='')
| 69 | |
| 70 | |
| 71 | def assert_(val, msg=''): |
| 72 | """ |
| 73 | Assert that works in release mode. |
| 74 | Accepts callable msg to allow deferring evaluation until failure. |
| 75 | |
| 76 | The Python built-in ``assert`` does not work when executing code in |
| 77 | optimized mode (the ``-O`` flag) - no byte-code is generated for it. |
| 78 | |
| 79 | For documentation on usage, refer to the Python documentation. |
| 80 | |
| 81 | """ |
| 82 | __tracebackhide__ = True # Hide traceback for py.test |
| 83 | if not val: |
| 84 | try: |
| 85 | smsg = msg() |
| 86 | except TypeError: |
| 87 | smsg = msg |
| 88 | raise AssertionError(smsg) |
| 89 | |
| 90 | |
| 91 | if os.name == 'nt': |
no outgoing calls