110 args = session.ctest_args
111 output_filename = args.get(
"output_file")
112 if not output_filename:
115 output = open(output_filename,
"w")
116 output_rootdir =
Path(output_filename).parent
118 coverage = args[
"coverage"].split(
",")
if args[
"coverage"]
else []
120 args[
"pytest_command"] +=
" --cov-report= --cov-reset " +
" ".join(
121 f
"--cov={module}" for module
in coverage
124 properties =
'LABELS "{}" '.
format(
";".join(args[
"label"]))
125 if args.get(
"binary_dir"):
126 properties += f
'ENVIRONMENT "CMAKE_CURRENT_BINARY_DIR={args["binary_dir"]}" '
127 properties +=
" ".join(args[
"properties"])
130 for path
in sorted(session.ctest_files):
132 args[
"prefix"] + os.path.relpath(path, args[
"pytest_root_dir"])
134 if name.endswith(
".py"):
136 pytest_cmd = args[
"pytest_command"]
139 TEST_DESC_TEMPLATE.format(
142 pytest_cmd=pytest_cmd,
143 properties=properties,
147 if session.ctest_fixture_setup.get(path):
149 'set_tests_properties('
150 f
'{name} PROPERTIES FIXTURES_SETUP "{";".join(session.ctest_fixture_setup[path])}")\n'
153 if session.ctest_fixture_required.get(path):
155 'set_tests_properties('
156 f
'{name} PROPERTIES FIXTURES_REQUIRED "{";".join(session.ctest_fixture_required[path])}")\n'
163 f
"set_tests_properties({name} PROPERTIES ENVIRONMENT COVERAGE_FILE={output_rootdir}/.coverage.{name})\n"
164 f
"set_tests_properties({name} PROPERTIES FIXTURES_SETUP {name})\n"
168 if coverage
and names:
169 combine_test = (args[
"prefix"] +
"coverage_combine").replace(
"/",
".")
170 combine_command = re.sub(
172 f
" combine {' '.join(f'{output_rootdir}/.coverage.{n}' for n in names)}",
173 args[
"coverage_command"],
176 TEST_DESC_TEMPLATE.format(
179 pytest_cmd=combine_command,
180 properties=properties,
184 f
"set_tests_properties({combine_test} PROPERTIES ENVIRONMENT COVERAGE_FILE={output_rootdir}/.coverage)\n"
185 f
"set_tests_properties({combine_test} PROPERTIES FIXTURES_REQUIRED \"{';'.join(names)}\")\n"
186 f
"set_tests_properties({combine_test} PROPERTIES FIXTURES_SETUP {combine_test})\n"
189 name = (args[
"prefix"] +
"coverage_report").replace(
"/",
".")
191 TEST_DESC_TEMPLATE.format(
194 pytest_cmd=f
"{args['coverage_command']}",
195 properties=properties +
" LABELS coverage",
200 f
"set_tests_properties({name} PROPERTIES ENVIRONMENT COVERAGE_FILE={output_rootdir}/.coverage)\n"
201 f
"set_tests_properties({name} PROPERTIES FIXTURES_REQUIRED {combine_test})\n"