diff --git a/HySoP/setup.py.in b/HySoP/setup.py.in
index 2f9c65cf30f39928bd0904d09c0cd2cd5c3812df..b33430f2d30cb20909602491610ebb1a27932d7b 100644
--- a/HySoP/setup.py.in
+++ b/HySoP/setup.py.in
@@ -99,12 +99,14 @@ config = Configuration(name=name,
 
 setup(**config.todict())
 
-cTestFile = open('@CMAKE_CURRENT_BINARY_DIR@/CTestTestfile.cmake','r')
-cTestStr = ""
-for line in cTestFile:
-    cTestStr += line.replace('BUILD_MAIN_PYTEST', config.get_build_temp_dir().replace('temp','lib')+'/parmepy/test/main_unit_tests.py')
-cTestFile.close()
-cTestFile = open('@CMAKE_CURRENT_BINARY_DIR@/CTestTestfile.cmake','w')
-cTestFile.write(cTestStr)
-cTestFile.close()
+# In case of cmake WITH_TESTS=ON
+if('@WITH_TESTS@' is "ON"):
+    cTestFile = open('@CMAKE_CURRENT_BINARY_DIR@/CTestTestfile.cmake','r')
+    cTestStr = ""
+    for line in cTestFile:
+        cTestStr += line.replace('BUILD_MAIN_PYTEST', config.get_build_temp_dir().replace('temp','lib')+'/parmepy/test/main_unit_tests.py')
+    cTestFile.close()
+    cTestFile = open('@CMAKE_CURRENT_BINARY_DIR@/CTestTestfile.cmake','w')
+    cTestFile.write(cTestStr)
+    cTestFile.close()