Skip to content

Commit 0c887a7

Browse files
committed
refactor(tests): don't hardcode temp file lines
1 parent 85cb99a commit 0c887a7

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

tests/commands/test_offboard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def mock_input_no(mock_input):
2020

2121

2222
@pytest.fixture
23-
def mock_NamedTemporaryFile(mock_NamedTemporaryFile):
24-
return mock_NamedTemporaryFile(MODULE, ["Overall Transfer Status: completed"])
23+
def mock_NamedTemporaryFile(mock_NamedTemporaryFile_with_readlines):
24+
return mock_NamedTemporaryFile_with_readlines(MODULE, ["Overall Transfer Status: completed"])
2525

2626

2727
@pytest.fixture

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def mock_google_user_is_staff(mock_module_name):
137137

138138

139139
@pytest.fixture
140-
def mock_NamedTemporaryFile(mocker):
140+
def mock_NamedTemporaryFile_with_readlines(mocker):
141141
"""Fixture returns a function that patches NamedTemporaryFile in a given module.
142142
143143
Optionally provide a value for GAM stdout.readlines().

tests/services/test_google.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ def mock_subprocess_call(mocker):
5050
return mocker.patch(f"{MODULE}.subprocess.call")
5151

5252

53-
@pytest.fixture
54-
def mock_NamedTemporaryFile(mock_NamedTemporaryFile):
55-
return mock_NamedTemporaryFile(MODULE, ["group"])
56-
57-
5853
def test_user_account_name_None():
5954
username = None
6055
account = user_account_name(username)
@@ -208,18 +203,20 @@ def test_user_in_group_user_does_not_exist(mock_google_user_exists, capfd):
208203
assert "User does not exist" in captured.out
209204

210205

211-
@pytest.mark.usefixtures("mock_NamedTemporaryFile", "mock_google_CallGAMCommand")
212-
def test_user_in_group_user_exists_in_group(mock_google_user_exists):
206+
@pytest.mark.usefixtures("mock_google_CallGAMCommand")
207+
def test_user_in_group_user_exists_in_group(mock_google_user_exists, mock_NamedTemporaryFile_with_readlines):
213208
mock_google_user_exists.return_value = True
209+
mock_NamedTemporaryFile_with_readlines(MODULE, ["group"])
214210

215211
res = user_in_group("username", "group")
216212

217213
assert res is True
218214

219215

220-
@pytest.mark.usefixtures("mock_NamedTemporaryFile", "mock_google_CallGAMCommand")
221-
def test_user_in_group_user_exists_not_in_group(mock_google_user_exists):
216+
@pytest.mark.usefixtures("mock_google_CallGAMCommand")
217+
def test_user_in_group_user_exists_not_in_group(mock_google_user_exists, mock_NamedTemporaryFile_with_readlines):
222218
mock_google_user_exists.return_value = True
219+
mock_NamedTemporaryFile_with_readlines(MODULE, ["group"])
223220

224221
res = user_in_group("username", "nope")
225222

0 commit comments

Comments
 (0)