Skip to content

Commit c0b8a81

Browse files
committed
use subprocess and assert the return code
Signed-off-by: Thomas Sjögren <[email protected]>
1 parent 0a6b254 commit c0b8a81

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

tests/test_vagrant.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ def test_vm_lifecycle(vm_dir):
286286
def test_valid_config(vm_dir):
287287
v = vagrant.Vagrant(vm_dir)
288288
v.up()
289-
output = v.validate()
290-
assert output.strip() == "Vagrantfile validated successfully."
289+
validation = v.validate(vm_dir)
290+
291+
assert validation.returncode == 0
291292

292293

293294
def test_vm_config(vm_dir):

vagrant/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,12 +876,19 @@ def plugin_list(self):
876876
output = self._run_vagrant_command(["plugin", "list", "--machine-readable"])
877877
return self._parse_plugin_list(output)
878878

879-
def validate(self):
879+
def validate(self, directory):
880880
"""
881881
This command validates present Vagrantfile.
882882
"""
883-
output = self._run_vagrant_command(["validate"])
884-
return output
883+
validate = subprocess.run(
884+
["vagrant", "validate"],
885+
cwd=directory,
886+
check=True,
887+
stdout=subprocess.PIPE,
888+
stderr=subprocess.PIPE,
889+
)
890+
891+
return validate
885892

886893
def _parse_plugin_list(self, output):
887894
"""

0 commit comments

Comments
 (0)