Skip to content

Commit

Permalink
tests: track when an entire category is skipped and be quieter
Browse files Browse the repository at this point in the history
There is no need to state for every single test that "preconditions were
not met". And logging the skip reason for a single test is easy to read,
but making every second line alternate is less so.
  • Loading branch information
eli-schwartz committed Jan 12, 2023
1 parent 901dc34 commit 58cfd8f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def get_paths(self, compiler: str, env: environment.Environment, installdir: Pat

@functools.total_ordering
class TestDef:
def __init__(self, path: Path, name: T.Optional[str], args: T.List[str], skip: bool = False):
def __init__(self, path: Path, name: T.Optional[str], args: T.List[str], skip: bool = False, skip_category: bool = False):
self.category = path.parts[1]
self.path = path
self.name = name
Expand All @@ -262,6 +262,7 @@ def __init__(self, path: Path, name: T.Optional[str], args: T.List[str], skip: b
self.installed_files = [] # type: T.List[InstalledFile]
self.do_not_set_opts = [] # type: T.List[str]
self.stdout = [] # type: T.List[T.Dict[str, str]]
self.skip_category = skip_category
self.skip_expected = False

# Always print a stack trace for Meson exceptions
Expand Down Expand Up @@ -789,7 +790,7 @@ def _skip_keys(test_def: T.Dict) -> T.Tuple[bool, bool]:
return (skip, skip_expected)


def load_test_json(t: TestDef, stdout_mandatory: bool) -> T.List[TestDef]:
def load_test_json(t: TestDef, stdout_mandatory: bool, skip_category: bool = False) -> T.List[TestDef]:
all_tests: T.List[TestDef] = []
test_def = {}
test_def_file = t.path / 'test.json'
Expand Down Expand Up @@ -899,7 +900,7 @@ def load_test_json(t: TestDef, stdout_mandatory: bool) -> T.List[TestDef]:
opts = [f'-D{x[0]}={x[1]}' for x in i if x[1] is not None]
skip = any([x[2] for x in i])
skip_expected = any([x[3] for x in i])
test = TestDef(t.path, name, opts, skip or t.skip)
test = TestDef(t.path, name, opts, skip or t.skip, skip_category)
test.env.update(env)
test.installed_files = installed
test.do_not_set_opts = do_not_set_opts
Expand All @@ -910,16 +911,16 @@ def load_test_json(t: TestDef, stdout_mandatory: bool) -> T.List[TestDef]:
return all_tests


def gather_tests(testdir: Path, stdout_mandatory: bool, only: T.List[str]) -> T.List[TestDef]:
def gather_tests(testdir: Path, stdout_mandatory: bool, only: T.List[str], skip_category: bool) -> T.List[TestDef]:
all_tests: T.List[TestDef] = []
for t in testdir.iterdir():
# Filter non-tests files (dot files, etc)
if not t.is_dir() or t.name.startswith('.'):
continue
if only and not any(t.name.startswith(prefix) for prefix in only):
continue
test_def = TestDef(t, None, [])
all_tests.extend(load_test_json(test_def, stdout_mandatory))
test_def = TestDef(t, None, [], skip_category=skip_category)
all_tests.extend(load_test_json(test_def, stdout_mandatory, skip_category))
return sorted(all_tests)


Expand Down Expand Up @@ -1120,7 +1121,7 @@ def __init__(self, category: str, subdir: str, skip: bool = False, stdout_mandat
assert key in categories, f'key `{key}` is not a recognized category'
all_tests = [t for t in all_tests if t.category in only.keys()]

gathered_tests = [(t.category, gather_tests(Path('test cases', t.subdir), t.stdout_mandatory, only[t.category]), t.skip) for t in all_tests]
gathered_tests = [(t.category, gather_tests(Path('test cases', t.subdir), t.stdout_mandatory, only[t.category], t.skip), t.skip) for t in all_tests]
return gathered_tests

def run_tests(all_tests: T.List[T.Tuple[str, T.List[TestDef], bool]],
Expand Down Expand Up @@ -1322,7 +1323,8 @@ def tqdm_print(*args: mlog.TV_Loggable, sep: str = ' ') -> None:

if is_skipped and skip_as_expected:
f.update_log(TestStatus.SKIP)
safe_print(bold('Reason:'), skip_reason)
if not t.skip_category:
safe_print(bold('Reason:'), skip_reason)
current_test = ET.SubElement(current_suite, 'testcase', {'name': testname, 'classname': t.category})
ET.SubElement(current_test, 'skipped', {})
continue
Expand Down

0 comments on commit 58cfd8f

Please sign in to comment.