(**new_env: str | Omit)
| 152 | |
| 153 | @contextlib.contextmanager |
| 154 | def update_env(**new_env: str | Omit) -> Iterator[None]: |
| 155 | old = os.environ.copy() |
| 156 | |
| 157 | try: |
| 158 | for name, value in new_env.items(): |
| 159 | if isinstance(value, Omit): |
| 160 | os.environ.pop(name, None) |
| 161 | else: |
| 162 | os.environ[name] = value |
| 163 | |
| 164 | yield None |
| 165 | finally: |
| 166 | os.environ.clear() |
| 167 | os.environ.update(old) |