(client, image)
| 264 | |
| 265 | @contextlib.contextmanager |
| 266 | def build_environment(client, image): |
| 267 | if client is not None: |
| 268 | container = client.containers.run( |
| 269 | image, command=["/bin/sleep", "86400"], detach=True |
| 270 | ) |
| 271 | td = None |
| 272 | context = ContainerContext(container) |
| 273 | else: |
| 274 | container = None |
| 275 | td = tempfile.TemporaryDirectory() |
| 276 | context = TempdirContext(td.name) |
| 277 | |
| 278 | try: |
| 279 | yield context |
| 280 | finally: |
| 281 | if container: |
| 282 | container.stop(timeout=0) |
| 283 | container.remove() |
| 284 | else: |
| 285 | td.cleanup() |
no test coverage detected