From 47cec1861327ab9f4689e4e13f7db0e23b90709b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 19 Mar 2021 17:26:37 +0800 Subject: [PATCH] cmake: use fixture for preparing venv 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 --- cmake/modules/AddCephTest.cmake | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cmake/modules/AddCephTest.cmake b/cmake/modules/AddCephTest.cmake index 2c8fdb0b938..e566a807cbc 100644 --- a/cmake/modules/AddCephTest.cmake +++ b/cmake/modules/AddCephTest.cmake @@ -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