Decorator to protect sys.dont_write_bytecode from mutation and to skip tests that require it to be set to False.
(fxn)
| 290 | |
| 291 | |
| 292 | def writes_bytecode_files(fxn): |
| 293 | """Decorator to protect sys.dont_write_bytecode from mutation and to skip |
| 294 | tests that require it to be set to False.""" |
| 295 | if sys.dont_write_bytecode: |
| 296 | return unittest.skip("relies on writing bytecode")(fxn) |
| 297 | @functools.wraps(fxn) |
| 298 | def wrapper(*args, **kwargs): |
| 299 | original = sys.dont_write_bytecode |
| 300 | sys.dont_write_bytecode = False |
| 301 | try: |
| 302 | to_return = fxn(*args, **kwargs) |
| 303 | finally: |
| 304 | sys.dont_write_bytecode = original |
| 305 | return to_return |
| 306 | return wrapper |
| 307 | |
| 308 | |
| 309 | def ensure_bytecode_path(bytecode_path): |