@@ -38,7 +38,10 @@ def pytest_collect_file(parent, path):
38
38
39
39
class MoleculeFile (pytest .File ):
40
40
def collect (self ):
41
- yield MoleculeItem ("" , self )
41
+ yield MoleculeItem ('test' , self )
42
+
43
+ def __str__ (self ):
44
+ return str (self .fspath .relto (os .getcwd ()))
42
45
43
46
44
47
class MoleculeItem (pytest .Item ):
@@ -50,21 +53,36 @@ def runtest(self):
50
53
cwd = os .path .abspath (os .path .join (self .fspath .dirname , '../..' ))
51
54
scenario = folders [- 1 ]
52
55
role = folders [- 3 ] # noqa
53
-
54
- cmd = ['python' , '-m' , 'molecule' , 'test' , '-s' , scenario ]
56
+ cmd = [sys .executable , '-m' , 'molecule' , self .name , '-s' , scenario ]
55
57
print ("running: %s (from %s)" % (" " .join (cmd ), cwd ))
56
- # Workaround for STDOUT/STDERR line ordering issue:
57
- # https://github.com/pytest-dev/pytest/issues/5449
58
- p = subprocess .Popen (
59
- cmd ,
60
- cwd = cwd ,
61
- stdout = subprocess .PIPE ,
62
- stderr = subprocess .STDOUT ,
63
- universal_newlines = True )
64
- for line in p .stdout :
65
- print (line , end = "" )
66
- p .wait ()
67
- assert p .returncode == 0
58
+
59
+ try :
60
+ # Workaround for STDOUT/STDERR line ordering issue:
61
+ # https://github.com/pytest-dev/pytest/issues/5449
62
+ p = subprocess .Popen (
63
+ cmd ,
64
+ cwd = cwd ,
65
+ stdout = subprocess .PIPE ,
66
+ stderr = subprocess .STDOUT ,
67
+ universal_newlines = True )
68
+ for line in p .stdout :
69
+ print (line , end = "" )
70
+ p .wait ()
71
+ if p .returncode != 0 :
72
+ pytest .fail (
73
+ "Error code %s returned by: %s" % (
74
+ p .returncode , " " .join (cmd )),
75
+ pytrace = False )
76
+ except Exception as e :
77
+ pytest .fail (
78
+ "Exception %s returned by: %s" % (e , " " .join (cmd )),
79
+ pytrace = False )
80
+
81
+ def reportinfo (self ):
82
+ return self .fspath , 0 , "usecase: %s" % self .name
83
+
84
+ def __str__ (self ):
85
+ return self .name
68
86
69
87
70
88
class MoleculeException (Exception ):
0 commit comments