Commit fd18ad7d authored by Kirill Smelkov's avatar Kirill Smelkov

Add built-in summary function for Pytest

Many project that use pytest for testing won't need to redefine it over
and over again in their .nxdtest file.
parent 0153635b
......@@ -64,7 +64,8 @@ import six
# loadNXDTestFile loads .nxdtest file located @path.
def loadNXDTestFile(path): # -> TestEnv
t = TestEnv()
g = {'TestCase': t.TestCase} # TODO + all other public TestEnv methods
g = {'TestCase': t.TestCase, # TODO + all other public TestEnv methods
'PyTest': PyTest}
with open(path, "r") as f:
src = f.read()
six.exec_(src, g)
......@@ -274,5 +275,33 @@ class LocalTestResultLine:
# XXX + dump .json ?
# support for well-known summary functions
class PyTest:
@staticmethod
def summary(out): # -> status_dict
# last line is like
# ================ 1 failed, 1 passed, 12 skipped in 0.39 seconds ================
textv = out.splitlines()
tail = textv[-1]
def get(name, default=None):
m = re.search(r'\b([0-9]+) '+name+r'\b', tail)
if m is None:
return default
return int(m.group(1))
stat = {}
def stat_set(stat_key, from_name):
v = get(from_name)
if v is None:
return
stat[stat_key] = v
stat_set('skip_count', 'skipped')
stat_set('error_count', 'failed')
stat_set('failure_count', 'xfailed') # XXX ok?
npass = get('passed', 0)
stat['test_count'] = npass + stat.get('failure_count', 0) + stat.get('skip_count', 0) + stat.get('error_count', 0)
return stat
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment