def s3_artifact(s3server): # `config_override` doesn't work here as decorator, probably because of generator with config_override(S3_ACCESS_KEY=ACCESS_KEY, S3_SECRET_KEY=SECRET_KEY): repo = S3ArtifactRepository(BUCKET_NAME, f'http://localhost:{s3server}') delete_bucket(repo) yield repo delete_bucket(repo)
def delete_bucket(repo: S3ArtifactRepository): if repo._bucket_exists(): bucket = repo._s3_res.Bucket(BUCKET_NAME) bucket.objects.all().delete() bucket.delete() buckets = repo._s3.list_buckets()['Buckets'] assert buckets == []