Skip to content

Commit 76afe8d

Browse files
crwilcoxleahecolegcf-merge-on-green[bot]
authored
fix: create fixture with random file name for test (#3067)
* fix: create fixture with random file name for test * fix: whitespace Co-authored-by: Leah E. Cole <[email protected]> Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com>
1 parent e92dc6a commit 76afe8d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

storage/api/crud_object_test.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,28 @@
1313

1414
import os
1515
import re
16+
import tempfile
1617

1718
from crud_object import main
19+
import pytest
1820

1921
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
2022

2123

22-
def test_main(capsys):
23-
main(BUCKET, __file__)
24+
@pytest.fixture()
25+
def test_file():
26+
_, file_path = tempfile.mkstemp()
27+
28+
with open(file_path, "w+b") as f:
29+
f.write(b"hello world")
30+
31+
yield file_path
32+
33+
os.remove(file_path)
34+
35+
36+
def test_main(capsys, test_file):
37+
main(BUCKET, test_file)
2438
out, err = capsys.readouterr()
2539

2640
assert not re.search(r'Downloaded file [!]=', out)

0 commit comments

Comments
 (0)