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()`
19 from pathlib
import Path
24 "--ctest-output-file",
25 type=argparse.FileType(
"w"),
26 help=
"name of the file to write to communicate to ctest the discovered tests",
29 "--ctest-pytest-command",
31 help=
"how pytest has to be invoked (e.g. using wrapper commands)",
34 "--ctest-pytest-root-dir",
36 help=
"root directory to compute test names",
41 help=
"string to prefix to the generated test names",
47 help=
"labels to attach to the test (the label pytest is always added)",
53 help=
"test properties to set for all discovered tests",
59 name[6:]: getattr(config.option, name)
60 for name
in dir(config.option)
61 if name.startswith(
"ctest_")
63 session.ctest_args = args
64 session.ctest_files = set(
65 item.path
if hasattr(item,
"path")
else Path(item.fspath)
for item
in items
69 TEST_DESC_TEMPLATE =
"""
70 add_test({name} {pytest_cmd} {path})
71 set_tests_properties({name} PROPERTIES {properties})
76 args = session.ctest_args
77 output = args.get(
"output_file")
82 properties =
'LABELS "{}" '.
format(
";".join(args[
"label"]))
83 properties +=
" ".join(args[
"properties"])
85 for path
in sorted(session.ctest_files):
87 args[
"prefix"] + os.path.relpath(path, args[
"pytest_root_dir"])
89 if name.endswith(
".py"):
92 TEST_DESC_TEMPLATE.format(
95 pytest_cmd=args[
"pytest_command"],
96 properties=properties,