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 <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2021-03-19 17:26:37 +08:00
parent 5b4a7668f1
commit 47cec18613

View 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