diff options
| author | Cedric Brandily <zzelle@gmail.com> | 2016-04-06 00:37:16 +0200 |
|---|---|---|
| committer | Cedric Brandily <zzelle@gmail.com> | 2016-04-06 00:40:44 +0200 |
| commit | 3c82c0e62e5b661d03ad7d9a3e93f95876805c2d (patch) | |
| tree | 59541e602d7163a28174dd0fb30d0f7f799b970b /functional/tests/compute | |
| parent | 139a45bb71ca2e99b0c8947c43c8d0165dec165e (diff) | |
| download | python-openstackclient-3c82c0e62e5b661d03ad7d9a3e93f95876805c2d.tar.gz | |
Improve tmpfile cleanup in functests
This change replaces when possible homemade temporary file management by
tempfile.NamedTemporaryFile[1][2] and defines only when needed a cleanup
for a temporary file[2].
[1] functional/tests/compute/v2/test_keypair.py
[2] functional/tests/object/v1/test_object.py
Change-Id: I728ab96381ca9f3fd1f899dd50e5ceb5e97b9397
Diffstat (limited to 'functional/tests/compute')
| -rw-r--r-- | functional/tests/compute/v2/test_keypair.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/functional/tests/compute/v2/test_keypair.py b/functional/tests/compute/v2/test_keypair.py index c9e8f3bc..d6c5ad28 100644 --- a/functional/tests/compute/v2/test_keypair.py +++ b/functional/tests/compute/v2/test_keypair.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import os +import tempfile import uuid from functional.common import test @@ -44,19 +44,18 @@ class KeypairTests(test.TestCase): cls.assertOutput('', raw_output) def test_keypair_create(self): - TMP_FILE = uuid.uuid4().hex - self.addCleanup(os.remove, TMP_FILE) - with open(TMP_FILE, 'w') as f: + with tempfile.NamedTemporaryFile() as f: f.write(PUBLIC_KEY) + f.flush() - raw_output = self.openstack( - 'keypair create --public-key ' + TMP_FILE + ' tmpkey', - ) - self.addCleanup( - self.openstack, - 'keypair delete tmpkey', - ) - self.assertIn('tmpkey', raw_output) + raw_output = self.openstack( + 'keypair create --public-key %s tmpkey' % f.name, + ) + self.addCleanup( + self.openstack, + 'keypair delete tmpkey', + ) + self.assertIn('tmpkey', raw_output) def test_keypair_list(self): opts = self.get_list_opts(self.HEADERS) |
