Skip to content

Commit

Permalink
Refactor persistent bucket cleanup in tests: manual clear, remove aut…
Browse files Browse the repository at this point in the history
…o-teardown, add error handling
  • Loading branch information
kris-konina-reef committed Sep 16, 2024
1 parent a171c1c commit d1b65f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 8 additions & 2 deletions test/integration/cleanup_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from .persistent_bucket import get_or_create_persistent_bucket


def test_cleanup_buckets(b2_api):
# this is not a test, but it is intended to be called
# via pytest because it reuses fixtures which have everything
# set up
pass # b2_api calls b2_api.clean_buckets() in its finalizer
# set up.
# The persistent bucket is cleared manually now and not
# when tests tear down, as otherwise we'd lose the main benefit
# of a persistent bucket, whose identity is shared across tests.
persistent_bucket = get_or_create_persistent_bucket(b2_api)
b2_api.clean_bucket(persistent_bucket)
b2_api.api.list_buckets()
14 changes: 5 additions & 9 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import sys
import tempfile
import uuid
from contextlib import suppress
from os import environ, path
from tempfile import TemporaryDirectory

import pytest
from b2sdk.v2 import B2_ACCOUNT_INFO_ENV_VAR, XDG_CONFIG_HOME_ENV_VAR, Bucket
from b2sdk.v2.exception import NonExistentBucket

from b2._internal.version_listing import (
CLI_VERSIONS,
Expand Down Expand Up @@ -437,12 +439,6 @@ def cleanup_persistent_bucket_subfolders(
):
yield
# Clean up all files in the persistent bucket after each test
bucket = b2_api.api.get_bucket_by_name(persistent_bucket_aggregate.bucket_name)
delete_files(bucket, persistent_bucket_aggregate.subfolder)


# @pytest.fixture(scope="session", autouse=True)
# def final_cleanup_persistent_buckets(b2_api, worker_id):
# yield
# if worker_id == "gw0":
# cleanup_persistent_bucket(b2_api)
with suppress(NonExistentBucket):
bucket = b2_api.api.get_bucket_by_name(persistent_bucket_aggregate.bucket_name)
delete_files(bucket, persistent_bucket_aggregate.subfolder)

0 comments on commit d1b65f5

Please sign in to comment.