diff --git a/demo/only.should b/demo/only.should new file mode 100644 index 0000000000000000000000000000000000000000..05485fd9699436b8e99aebfbed211782db02751b --- /dev/null +++ b/demo/only.should @@ -0,0 +1,7 @@ + +./should --only-f demo/cal.should + +$ Launch only the two 'f' tests +r:Summary.* TODO:1 +r:Summary.* TODO-but-ok:1 +r:Summary.* total:2 diff --git a/src/should.py b/src/should.py index 25f2a0d1170890e57e4b13e1a3128bcdd3cd4b27..589f1a6120644935e3418554b6054905477de08b 100755 --- a/src/should.py +++ b/src/should.py @@ -227,6 +227,10 @@ for p in (parser, options): parser.add_argument('--shuffle', action='store_true', help='shuffle the tests') +group = parser.add_argument_group('filter options') + +group.add_argument('--only-f', action='store_true', help="launches only 'f' tests") + output = parser.add_argument_group('output options') output.add_argument('--log', action='append_const', dest='output', const=OUT_LOG, help='stores the output into .log files') @@ -426,6 +430,7 @@ class ExternalTestCase(TestCaseAbstract): self.name = name self.status = status self.info = info + self.modifiers = '' def str_additional_status(self, verbose = False): s = '' @@ -748,7 +753,7 @@ class TestSuite(): self.stats.up(test.status) self.status = SKIP - def test(self, variables=[], verbose=0, colorize=True): + def test(self, variables=[], verbose=0, colorize=True, only=None): self.variables_all = self.variables + variables if verbose > 1: @@ -814,6 +819,13 @@ class TestSuite(): self.test_lines = open(self.source).readlines() if self.source else self.stdout for test in self.tests: + # Filter + if only: + if not only(test): + test.status = SKIP + continue + + # Test the test test.test(self.test_lines, variables=self.variables_all, verbose=verbose-1) self.stats.up(test.status) @@ -907,7 +919,7 @@ class FileSet(): def __len__(self): return len(self.files) - def test(self, variables=None, cd=None, cd_same=False, output=None, verbose=0): + def test(self, variables=None, cd=None, cd_same=False, output=None, verbose=0, only=None): self.status = True try: @@ -919,7 +931,7 @@ class FileSet(): self.sets.append(s) s.load(open(f)) - s.test(variables, verbose - 1) + s.test(variables, verbose - 1, only=only) self.stats.up(s.status, f) if not s.status: self.status = False @@ -1033,8 +1045,14 @@ if __name__ == '__main__': print("Shuffling test files") random.shuffle(args.file) + # Filters + only = None + if args.only_f: + only = lambda test: MOD_TODO in test.modifiers + + # Launch tests fs = FileSet(args.file, timeout = args.timeout, modifiers=''.join(args.mod if args.mod else [])) - status = fs.test(variables = variables, cd = args.cd, cd_same = args.cd_same, output = args.output, verbose = args.verbose) + status = fs.test(variables = variables, cd = args.cd, cd_same = args.cd_same, output = args.output, verbose = args.verbose, only = only) if len(fs) > 1: retry = fs.write_retry(sys.argv[1:], args.file, verbose = args.verbose)