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