Skip to content

Commit 6b78914

Browse files
Use pyfakefs for TestSqliteAccountProfileFileLocation
1 parent 00f89e9 commit 6b78914

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

noxfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"pytest-cov==3.0.0",
3131
"pytest-mock==3.6.1",
3232
'pytest-lazy-fixture==0.6.3',
33+
'pyfakefs==4.5.6',
3334
]
3435
REQUIREMENTS_BUILD = ['setuptools>=20.2']
3536

@@ -107,7 +108,7 @@ def unit(session):
107108
"""Run unit tests."""
108109
install_myself(session)
109110
session.install(*REQUIREMENTS_TEST)
110-
args = ['--doctest-modules']
111+
args = ['--doctest-modules', '-p', 'pyfakefs']
111112
if not SKIP_COVERAGE:
112113
args += ['--cov=b2sdk', '--cov-branch', '--cov-report=xml']
113114
# TODO: Use session.parametrize for apiver

test/unit/account_info/test_sqlite_account_info.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ def test_migrate_to_4(self):
6868

6969
class TestSqliteAccountProfileFileLocation:
7070
@pytest.fixture(autouse=True)
71-
def setup(self, monkeypatch):
71+
def setup(self, monkeypatch, fs):
7272
monkeypatch.delenv(B2_ACCOUNT_INFO_ENV_VAR, raising=False)
7373
monkeypatch.delenv(XDG_CONFIG_HOME_ENV_VAR, raising=False)
74-
if os.path.exists(os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE)):
75-
os.remove(os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE))
7674

7775
def test_invalid_profile_name(self):
7876
with pytest.raises(ValueError):
@@ -112,7 +110,10 @@ def test_env_var(self, monkeypatch):
112110
def test_default_file_if_exists(self, monkeypatch):
113111
# ensure that XDG_CONFIG_HOME_ENV_VAR doesn't matter if default file exists
114112
monkeypatch.setenv(XDG_CONFIG_HOME_ENV_VAR, 'some')
115-
with open(os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE), 'w') as account_file:
113+
account_file_path = os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE)
114+
parent_dir = os.path.abspath(os.path.join(account_file_path, os.pardir))
115+
os.makedirs(parent_dir, exist_ok=True)
116+
with open(account_file_path, 'w') as account_file:
116117
account_file.write('')
117118
account_info_path = SqliteAccountInfo._get_user_account_info_path()
118119
assert account_info_path == os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE)

0 commit comments

Comments
 (0)