Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
env:
PYTHON_DEFAULT_VERSION: "3.11"

concurrency: continuous-integration

jobs:
lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -78,6 +80,7 @@ jobs:
B2_TEST_APPLICATION_KEY_ID: ${{ secrets.B2_TEST_APPLICATION_KEY_ID }}
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 5
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* GitHub CI uses GITHUB_OUTPUT instead of deprecated set-output
* Releases now feature digests of each file
* Change default Python version in CI/CD to 3.11
* Fix bucket leaks in integration tests
* Allow only one CI workflow at a time
* Re-enable pytest-xdist for integration tests

## [3.6.0] - 2022-09-20

Expand Down
2 changes: 1 addition & 1 deletion test/integration/cleanup_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ 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
b2_api.clean_buckets()
b2_api.clean_all_buckets()
71 changes: 30 additions & 41 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
import pytest

from b2sdk.v2 import B2_ACCOUNT_INFO_ENV_VAR, XDG_CONFIG_HOME_ENV_VAR
from b2sdk.exception import BucketIdNotFound
from b2sdk.exception import BucketIdNotFound, NonExistentBucket

from .helpers import Api, CommandLine, bucket_name_part

GENERAL_BUCKET_NAME_PREFIX = 'clitst'
from .helpers import Api, CommandLine


@pytest.hookimpl
Expand Down Expand Up @@ -52,32 +50,16 @@ def realm() -> str:


@pytest.fixture(scope='function')
def bucket_name(b2_api) -> str:
bucket = b2_api.create_bucket()
yield bucket.name
with contextlib.suppress(BucketIdNotFound):
b2_api.clean_bucket(bucket)


@pytest.fixture(scope='function') # , autouse=True)
def debug_print_buckets(b2_api):
print('-' * 30)
print('Buckets before test ' + environ['PYTEST_CURRENT_TEST'])
num_buckets = b2_api.count_and_print_buckets()
print('-' * 30)
try:
yield
finally:
print('-' * 30)
print('Buckets after test ' + environ['PYTEST_CURRENT_TEST'])
delta = b2_api.count_and_print_buckets() - num_buckets
print(f'DELTA: {delta}')
print('-' * 30)
def create_test_bucket(b2_api):
def factory(*args, **kwargs):
return b2_api.create_test_bucket(*args, **kwargs).name

return factory

@pytest.fixture(scope='session')
def this_run_bucket_name_prefix() -> str:
yield GENERAL_BUCKET_NAME_PREFIX + bucket_name_part(8)

@pytest.fixture(scope='function')
def bucket_name(create_test_bucket) -> str:
return create_test_bucket()


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -108,23 +90,14 @@ def auto_change_account_info_dir(monkey_patch) -> dir:


@pytest.fixture(scope='module')
def b2_api(application_key_id, application_key, realm, this_run_bucket_name_prefix) -> Api:
yield Api(
application_key_id, application_key, realm, GENERAL_BUCKET_NAME_PREFIX,
this_run_bucket_name_prefix
)
def b2_api(application_key_id, application_key, realm) -> Api:
return Api(application_key_id, application_key, realm)


@pytest.fixture(scope='module')
def b2_tool(
request, application_key_id, application_key, realm, this_run_bucket_name_prefix
) -> CommandLine:
def b2_tool(request, application_key_id, application_key, realm) -> CommandLine:
tool = CommandLine(
request.config.getoption('--sut'),
application_key_id,
application_key,
realm,
this_run_bucket_name_prefix,
request.config.getoption('--sut'), application_key_id, application_key, realm
)
tool.reauthorize(check_key_capabilities=True) # reauthorize for the first time (with check)
return tool
Expand All @@ -134,3 +107,19 @@ def b2_tool(
def auto_reauthorize(request, b2_tool):
""" Automatically reauthorize for each test (without check) """
b2_tool.reauthorize(check_key_capabilities=False)


@pytest.fixture(scope='function', autouse=True)
def auto_clean_buckets(b2_api, b2_tool):
"""Automatically delete created buckets after each test case"""
yield

# remove buckets created using the CLI
while b2_tool.buckets:
with contextlib.suppress(BucketIdNotFound, NonExistentBucket):
# The buckets were created with the CLI tool, but we still delete them using the API as it will handle
# corner cases properly (like retries or deleting non-empty buckets).
b2_api.clean_bucket(b2_tool.buckets.pop())

# remove buckets created using the API
b2_api.clean_buckets()
Loading