# About the behaviour of CTEST\_CUSTOM\_PRE\_TEST

**URL:** <https://discourse.cmake.org/t/about-the-behaviour-of-ctest-custom-pre-test/6298>\
**Category:** Code\
**Created:** [August 18, 2022, 3:33pm UTC](https://discourse.cmake.org/t/about-the-behaviour-of-ctest-custom-pre-test/6298 "2022-08-18T15:33:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bicen\_Zhu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bicen_zhu/32/2692_2.png) [@Bicen\_Zhu](https://discourse.cmake.org/u/Bicen_Zhu)\
**Post date:** [August 18, 2022, 3:33pm UTC](https://discourse.cmake.org/t/about-the-behaviour-of-ctest-custom-pre-test/6298/1 "2022-08-18T15:33:39Z")

</div>

Hello,

Have a problem when using `CTEST_CUSTOM_PRE_TEST` to start a daemon. After the daemon started, ctest still wait it exit  
For example I have a python daemon, when I run it by command `python3 myDaemon.py`, it returns to the shell prompt quickly, and the myDaemon.py work as a daemon. But it I set

set(CTEST\_CUSTOM\_PRE\_TEST “python3 myDaemon.py")

The ctest blocks to wait it return and none of the tests starts running

I am wondering how could I change the behaviors of CTEST\_CUSTOM\_PRE\_TEST, let it not block

I even tried to use execute\_process and specify the INPUT\_FILE, OUTPUT\_FILE, ERROR\_FILE, it will not block. How do I set similar options for the CTEST\_CUSTOM\_PRE\_TEST

execute\_process(  
COMMAND python3 myDaemon.py  
INPUT\_FILE /Users/bzhu/PycharmProjects/httpDaemon/[psql.in](http://psql.in)  
OUTPUT\_FILE /Users/bzhu/PycharmProjects/httpDaemon/psql.out  
ERROR\_FILE /Users/bzhu/PycharmProjects/httpDaemon/psql.err  
RESULT\_VARIABLE result  
)

Thank you

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [September 1, 2022, 10:22pm UTC](https://discourse.cmake.org/t/about-the-behaviour-of-ctest-custom-pre-test/6298/2 "2022-09-01T22:22:58Z")

</div>

@craig.scott would you happen to know more about `CTEST_CUSTOM_PRE_TEST`?

---

<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:** [September 2, 2022, 3:03am UTC](https://discourse.cmake.org/t/about-the-behaviour-of-ctest-custom-pre-test/6298/3 "2022-09-02T03:03:36Z")

</div>

I don’t use it myself. For situations like this, I use test fixtures instead. I define a test case which starts up the server and another one which shuts it down. I define a fixture name (say `DB`). I set the startup test’s `FIXTURES_SETUP` property to the fixture name, the shutdown test’s `FIXTURES_CLEANUP` property to the fixture name, and any test that needs to access the server will list the fixture name in its own `FIXTURES_REQUIRED` property. See the [FIXTURES\_REQUIRED](https://cmake.org/cmake/help/latest/prop_test/FIXTURES_REQUIRED.html) test property docs for examples.

I find the main wrinkle with the above is getting a platform independent way of starting a process in the background and leaving it running, then having a platform independent way for the shutdown test to robustly know what process it has to terminate and be able to do so. If you don’t care about supporting Windows, it isn’t too painful, but I would dread having to make this work across all major platforms. You may want to consider implementing the startup and shutdown steps in something like python to try to minimise the platform-dependent pain.
