Commit 6991af9b authored by Kirill Smelkov's avatar Kirill Smelkov

--list and --run

- To list which tests are in there,
- To execute only selected tests.

Apply only to local mode.
Very handy for debugging.
parent 39e89cc0
...@@ -112,7 +112,15 @@ def main(): ...@@ -112,7 +112,15 @@ def main():
parser.add_argument('--verbose', action='store_true', help='increase output verbosity') parser.add_argument('--verbose', action='store_true', help='increase output verbosity')
local = parser.add_argument_group('local run')
local.add_argument('-l', '--list', action='store_true', help='Only list tests')
local.add_argument('-k', '--run', help='Run only tests whose names match provided expression')
args = parser.parse_args() args = parser.parse_args()
if args.master_url is not None:
if args.list or args.run:
print('E: local options can be used only without --master_url', file=sys.stderr)
sys.exit(2)
# if verbose -> log to stderr # if verbose -> log to stderr
logger = None logger = None
...@@ -123,6 +131,12 @@ def main(): ...@@ -123,6 +131,12 @@ def main():
# load list of tests to run # load list of tests to run
tenv = loadNXDTestFile('.nxdtest') tenv = loadNXDTestFile('.nxdtest')
# --list
if args.list:
for t in tenv.testv:
print(t.name)
return
# master_url provided -> run tests under master control # master_url provided -> run tests under master control
if args.master_url is not None: if args.master_url is not None:
# connect to master and create 'test result' object with list of tests to run # connect to master and create 'test result' object with list of tests to run
...@@ -140,7 +154,7 @@ def main(): ...@@ -140,7 +154,7 @@ def main():
# master_url not provided -> run tests locally # master_url not provided -> run tests locally
else: else:
test_result = LocalTestResult(tenv) test_result = LocalTestResult(tenv, run=args.run)
# make sure we get output from subprocesses without delay. # make sure we get output from subprocesses without delay.
# go does not buffer stdout/stderr by default, but python does for stdout. # go does not buffer stdout/stderr by default, but python does for stdout.
...@@ -279,19 +293,27 @@ def test_result_summary(name, kw): ...@@ -279,19 +293,27 @@ def test_result_summary(name, kw):
# LocalTestResult* handle tests runs, when master_url was not provided and tests are run locally. # LocalTestResult* handle tests runs, when master_url was not provided and tests are run locally.
class LocalTestResult: class LocalTestResult:
def __init__(self, tenv): def __init__(self, tenv, run=None):
assert isinstance(tenv, TestEnv) assert isinstance(tenv, TestEnv)
self.tenv = tenv self.tenv = tenv
self.next = 0 # tenv.testv[next] is next test to execute self.next = 0 # tenv.testv[next] is next test to consider executing
self.run = run # None | re to filter which tests to execute
def start(self): # -> test_result_line def start(self): # -> test_result_line
if self.next >= len(self.tenv.testv): while 1:
return None # all tests are done if self.next >= len(self.tenv.testv):
return None # all tests are done
t = self.tenv.testv[self.next]
self.next += 1
# --run
if self.run is not None and not re.match(self.run, t.name):
continue
test_result_line = LocalTestResultLine() test_result_line = LocalTestResultLine()
test_result_line.name = self.tenv.testv[self.next].name test_result_line.name = t.name
self.next += 1 return test_result_line
return test_result_line
class LocalTestResultLine: class LocalTestResultLine:
def stop(self, **kw): def stop(self, **kw):
......
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