[Storage]Use tempfile instead of hardcoded name
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
+import tempfile
import pytest
@@ -16,6 +17,7 @@ from os import (
urandom,
path,
remove,
+ unlink
)
from azure.core.exceptions import HttpResponseError
@@ -666,13 +668,15 @@ class StorageBlobEncryptionTest(StorageTestCase):
stream = BytesIO(content)
self._create_blob_from_star(BlobType.PageBlob, content, stream, length=512)
- file_name = 'page_blob_from_star.temp.dat'
- with open(file_name, 'wb') as stream:
+ stream = tempfile.NamedTemporaryFile(delete=False)
+ path_name = stream.name
stream.write(content)
+ stream.close()
- with open(file_name, 'rb') as stream:
+ with open(path_name, 'rb') as stream:
self._create_blob_from_star(BlobType.PageBlob, content, stream)
- self._teardown(file_name)
+
+ unlink(stream.name)
def _create_blob_from_star(self, blob_type, content, data, **kwargs):
blob_name = self._get_blob_reference(blob_type)
