Skip to content

Commit df643f7

Browse files
committed
Set temporary directory as account info config dir in integration tests
1 parent c884f6f commit df643f7

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
######################################################################
2+
#
3+
# File: b2sdk/_internal/testing/fixtures/account_info.py
4+
#
5+
# Copyright 2025 Backblaze Inc. All Rights Reserved.
6+
#
7+
# License https://www.backblaze.com/using_b2_code.html
8+
#
9+
######################################################################
10+
from os import path
11+
12+
import pytest
13+
14+
from b2sdk._internal.account_info.sqlite_account_info import (
15+
B2_ACCOUNT_INFO_ENV_VAR,
16+
XDG_CONFIG_HOME_ENV_VAR,
17+
)
18+
19+
20+
@pytest.fixture(scope='session')
21+
def change_account_info_dir(monkeysession, tmp_path_factory):
22+
"""
23+
Automatically for the whole testing:
24+
1) temporary remove B2_APPLICATION_KEY and B2_APPLICATION_KEY_ID from environment
25+
2) create a temporary directory for storing account info database
26+
3) set B2_ACCOUNT_INFO_ENV_VAR to point to the temporary account info file
27+
"""
28+
29+
monkeysession.delenv('B2_APPLICATION_KEY_ID', raising=False)
30+
monkeysession.delenv('B2_APPLICATION_KEY', raising=False)
31+
32+
temp_dir = tmp_path_factory.mktemp('b2_config')
33+
34+
monkeysession.setenv(B2_ACCOUNT_INFO_ENV_VAR, path.join(temp_dir, '.b2_account_info'))
35+
monkeysession.setenv(XDG_CONFIG_HOME_ENV_VAR, temp_dir)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
######################################################################
2+
#
3+
# File: b2sdk/_internal/testing/fixtures/common.py
4+
#
5+
# Copyright 2025 Backblaze Inc. All Rights Reserved.
6+
#
7+
# License https://www.backblaze.com/using_b2_code.html
8+
#
9+
######################################################################
10+
import pytest
11+
12+
13+
@pytest.fixture(scope='session')
14+
def monkeysession():
15+
with pytest.MonkeyPatch.context() as mp:
16+
yield mp

b2sdk/v3/testing/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@
4545
bucket,
4646
b2_subfolder,
4747
)
48+
from b2sdk._internal.testing.fixtures.common import monkeysession
49+
from b2sdk._internal.testing.fixtures.account_info import change_account_info_dir
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set temporary directory as account info config dir in integration tests.

test/integration/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
3+
4+
@pytest.fixture(scope='session', autouse=True)
5+
def auto_change_account_info_dir(change_account_info_dir):
6+
pass

0 commit comments

Comments
 (0)