Skip to content

Commit 898c52a

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

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from os import path
2+
3+
import pytest
4+
5+
from b2sdk._internal.account_info.sqlite_account_info import (
6+
B2_ACCOUNT_INFO_ENV_VAR,
7+
XDG_CONFIG_HOME_ENV_VAR,
8+
)
9+
10+
11+
@pytest.fixture(scope='session')
12+
def change_account_info_dir(monkeysession, tmp_path_factory):
13+
"""
14+
Automatically for the whole testing:
15+
1) temporary remove B2_APPLICATION_KEY and B2_APPLICATION_KEY_ID from environment
16+
2) create a temporary directory for storing account info database
17+
3) set B2_ACCOUNT_INFO_ENV_VAR to point to the temporary account info file
18+
"""
19+
20+
monkeysession.delenv('B2_APPLICATION_KEY_ID', raising=False)
21+
monkeysession.delenv('B2_APPLICATION_KEY', raising=False)
22+
23+
temp_dir = tmp_path_factory.mktemp('b2_config')
24+
25+
monkeysession.setenv(B2_ACCOUNT_INFO_ENV_VAR, path.join(temp_dir, '.b2_account_info'))
26+
monkeysession.setenv(XDG_CONFIG_HOME_ENV_VAR, temp_dir)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
3+
4+
@pytest.fixture(scope='session')
5+
def monkeysession():
6+
with pytest.MonkeyPatch.context() as mp:
7+
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)