]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: use fixture for preparing venv 40235/head
authorKefu Chai <kchai@redhat.com>
Fri, 19 Mar 2021 09:26:37 +0000 (17:26 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 24 Mar 2021 14:19:31 +0000 (22:19 +0800)
this change should allow us to decouple "ninja tests" from "ctest".
in other words, we can just run

ctest -R run-tox-python-common -V

without running "ninja tests" first. before this change

${name}-venv is added as a dependency of "tests" target.

after this change,

setup-venv-for-${name} is added as a test, which is in turn a test of
run-tox-${name}, so we can just

ctest -R run-tox-${name}

now for preparing the venv and then testing the tox test of ${name}.

Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/AddCephTest.cmake

index 2c8fdb0b93852c24ee725b603a522a5d02693b4d..e566a807cbc076d9bea509b544d710da1d899596 100644 (file)
@@ -70,14 +70,17 @@ function(add_tox_test name)
   endif()
   string(REPLACE ";" "," tox_envs "${tox_envs}")
   find_package(Python3 QUIET REQUIRED)
-  add_custom_command(
-    OUTPUT ${venv_path}/bin/activate
-    COMMAND ${CMAKE_SOURCE_DIR}/src/tools/setup-virtualenv.sh --python="${Python3_EXECUTABLE}" ${venv_path}
-    WORKING_DIRECTORY ${tox_path}
-    COMMENT "preparing venv for ${name}")
-  add_custom_target(${name}-venv
-    DEPENDS ${venv_path}/bin/activate)
-  add_dependencies(tests ${name}-venv)
+  add_test(
+    NAME setup-venv-for-${name}
+    COMMAND ${CMAKE_SOURCE_DIR}/src/tools/setup-virtualenv.sh --python=${Python3_EXECUTABLE} ${venv_path}
+    WORKING_DIRECTORY ${tox_path})
+  set_tests_properties(setup-venv-for-${name} PROPERTIES
+    FIXTURES_SETUP venv-for-${name})
+  add_test(
+    NAME teardown-venv-for-${name}
+    COMMAND ${CMAKE_COMMAND} -E remove_directory ${venv_path})
+  set_tests_properties(teardown-venv-for-${name} PROPERTIES
+    FIXTURES_CLEANUP venv-for-${name})
   add_test(
     NAME ${test_name}
     COMMAND ${CMAKE_SOURCE_DIR}/src/script/run_tox.sh
@@ -86,6 +89,8 @@ function(add_tox_test name)
               --tox-path ${tox_path}
               --tox-envs ${tox_envs}
               --venv-path ${venv_path})
+  set_tests_properties(${test_name} PROPERTIES
+    FIXTURES_REQUIRED venv-for-${name})
   set_property(
     TEST ${test_name}
     PROPERTY ENVIRONMENT