From df78cfe9be48cb7ead29d64682ae039fd1812b99 Mon Sep 17 00:00:00 2001 From: Freddy Tan Date: Wed, 21 Dec 2016 00:55:55 +0800 Subject: [PATCH] fix teardown --- test/test_terraform.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/test_terraform.py b/test/test_terraform.py index ab592ea..a190b15 100644 --- a/test/test_terraform.py +++ b/test/test_terraform.py @@ -3,6 +3,7 @@ import pytest import os import logging import re +import shutil logging.basicConfig(level=logging.DEBUG) current_path = os.path.dirname(os.path.realpath(__file__)) @@ -31,6 +32,19 @@ CMD_CASES = [ ] ] +@pytest.fixture() +def fmt_test_file(request): + target = os.path.join(current_path, 'bad_fmt', 'test.backup') + orgin = os.path.join(current_path, 'bad_fmt', 'test.tf') + shutil.copy(orgin, + target) + + def td(): + shutil.move(target, orgin) + + request.addfinalizer(td) + return + class TestTerraform(object): def teardown_method(self, method): @@ -86,13 +100,11 @@ class TestTerraform(object): ('fmt', ['bad_fmt'], {'list': False, 'diff': False}) ] ) - def test_options(self, cmd, args, options): + def test_options(self, cmd, args, options, fmt_test_file): tf = Terraform(working_dir=current_path) ret, out, err = getattr(tf, cmd)(*args, **options) assert ret == 0 assert out == '' - # todo revert the test file - def test_state_data(self): cwd = os.path.join(current_path, 'test_tfstate_file')