# Use case for TEST\_INCLUDE\_FILES directory property?

**URL:** <https://discourse.cmake.org/t/use-case-for-test-include-files-directory-property/6864>\
**Category:** Code\
**Created:** [November 14, 2022, 4:05am UTC](https://discourse.cmake.org/t/use-case-for-test-include-files-directory-property/6864 "2022-11-14T04:05:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)\
**Post date:** [November 14, 2022, 4:05am UTC](https://discourse.cmake.org/t/use-case-for-test-include-files-directory-property/6864/1 "2022-11-14T04:05:44Z")

</div>

What is the intended use case for the `TEST_INCLUDE_FILES` directory property?

The docs say:

> A list of cmake files that will be included when ctest is run. If you specify `TEST_INCLUDE_FILES`, those files will be included and processed when ctest is run on the directory.

Is this intended to allow you to run some setup tasks before ctest executes tests?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [November 14, 2022, 9:27pm UTC](https://discourse.cmake.org/t/use-case-for-test-include-files-directory-property/6864/2 "2022-11-14T21:27:21Z")

</div>

It allows you to execute arbitrary code at test time. But by test time, I don’t mean during a test case, I mean when `ctest` runs, specifically while it is reading the files to build up its picture of the set of defined tests.

One example use case is with `gtest_discover_tests()`. That command allows you to specify properties to set on test cases, but it can’t set a value that is a list, only single values. If you need to assign a list to some test property, you need to do that in a separate file, which you then add to `ctest` processing by listing that file in the `TEST_INCLUDE_FILES` property. The `TEST_LIST` keyword allows you to specify what variable to store the list of discovered tests in so that you can set properties on those tests.

_CMakeLists.txt_

```cmake
gtest_discover_tests(SomeTarget TEST_LIST discovered_tests)
set_property(DIRECTORY APPEND PROPERTY
    TEST_INCLUDE_FILES ${CMAKE_CURRENT_LIST_DIR}/add_labels.cmake
)

```

_add\_labels.cmake_

```cmake
set_tests_properties(${discovered_tests} PROPERTIES LABELS "One;Two;Three")

```

---

<div class="post-metadata">

**Author:** ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)\
**Post date:** [November 14, 2022, 9:29pm UTC](https://discourse.cmake.org/t/use-case-for-test-include-files-directory-property/6864/3 "2022-11-14T21:29:31Z")

</div>

Interesting. So in the files included by `TEST_INCLUDE_FILES`, the variables in that scope of CMake processing are available?

So, is CTest actually re-executing cmake configuration as it builds the test graph? I didn’t realize that.

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [November 14, 2022, 9:51pm UTC](https://discourse.cmake.org/t/use-case-for-test-include-files-directory-property/6864/4 "2022-11-14T21:51:45Z")

</div>

> [@benthevining](#):
>
> So in the files included by `TEST_INCLUDE_FILES`, the variables in that scope of CMake processing are available?

No it is a completely separate processing environment. It is isolated from the CMake configure run. All you have access to is whatever is defined in the files `ctest` reads. Imagine it like a separate `cmake -P` invocation.

---

<div class="post-metadata">

**Author:** ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)\
**Post date:** [November 14, 2022, 10:08pm UTC](https://discourse.cmake.org/t/use-case-for-test-include-files-directory-property/6864/5 "2022-11-14T22:08:58Z")

</div>

I see. Thanks for the info!
