12 pytest plugin that report collected pytest files as CTest tests
14 This plugin is not meant to be used directly, but it is invoked by the
15 CMake function `gaudi_add_pytest()`
20 from pathlib
import Path
25 "--ctest-output-file",
26 type=argparse.FileType(
"w"),
27 help=
"name of the file to write to communicate to ctest the discovered tests",
30 "--ctest-pytest-command",
32 help=
"how pytest has to be invoked (e.g. using wrapper commands)",
35 "--ctest-pytest-root-dir",
37 help=
"root directory to compute test names",
42 help=
"string to prefix to the generated test names",
48 help=
"labels to attach to the test (the label pytest is always added)",
54 help=
"test properties to set for all discovered tests",
60 name[6:]: getattr(config.option, name)
61 for name
in dir(config.option)
62 if name.startswith(
"ctest_")
64 session.ctest_args = args
65 session.ctest_files = set(
66 item.path
if hasattr(item,
"path")
else Path(item.fspath)
for item
in items
70 TEST_DESC_TEMPLATE =
"""
71 add_test({name} {pytest_cmd} {path})
72 set_tests_properties({name} PROPERTIES {properties})
77 args = session.ctest_args
78 output = args.get(
"output_file")
83 properties =
'LABELS "{}" '.
format(
";".join(args[
"label"]))
84 properties +=
" ".join(args[
"properties"])
86 for path
in sorted(session.ctest_files):
88 args[
"prefix"] + os.path.relpath(path, args[
"pytest_root_dir"])
90 if name.endswith(
".py"):
93 TEST_DESC_TEMPLATE.format(
96 pytest_cmd=args[
"pytest_command"],
97 properties=properties,