(**new_env: str | Omit)
| 169 | |
| 170 | @contextlib.contextmanager |
| 171 | def update_env(**new_env: str | Omit) -> Iterator[None]: |
| 172 | old = os.environ.copy() |
| 173 | |
| 174 | try: |
| 175 | for name, value in new_env.items(): |
| 176 | if isinstance(value, Omit): |
| 177 | os.environ.pop(name, None) |
| 178 | else: |
| 179 | os.environ[name] = value |
| 180 | |
| 181 | yield None |
| 182 | finally: |
| 183 | os.environ.clear() |
| 184 | os.environ.update(old) |