diff --git a/CMakeLists.txt b/CMakeLists.txt index fba23f92d6..6a3362badb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,7 @@ option(BUILD_DIRECT "Build the direct source tree." ON) option(BUILD_PANDATOOL "Build the pandatool source tree." ON) option(BUILD_CONTRIB "Build the contrib source tree." ON) option(BUILD_MODELS "Build/install the built-in models." ON) +option(BUILD_TESTS "Build unit test runner." ON) option(BUILD_TOOLS "Build binary tools." ON) # Include Panda3D packages @@ -166,17 +167,8 @@ if(BUILD_MODELS) COMPONENT Models DESTINATION ${CMAKE_INSTALL_DATADIR}/panda3d) endif() -if(INTERROGATE_PYTHON_INTERFACE) - # If we built the Python interface, run the test suite. Note, we do NOT test - # for pytest before adding this test. If the user doesn't have pytest, we'd - # like for the tests to fail. - - # In the Coverage configuration, we also require pytest-cov - - add_test(NAME pytest - COMMAND "${PYTHON_EXECUTABLE}" -m pytest "${PROJECT_SOURCE_DIR}/tests" - $<$:--cov=.> - WORKING_DIRECTORY "${PANDA_OUTPUT_DIR}") +if(BUILD_TESTS) + add_subdirectory(tests "${CMAKE_BINARY_DIR}/tests") endif() # Generate the Panda3DConfig.cmake file so find_package(Panda3D) works, and diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000000..f3c56a38bc --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,20 @@ +if(NOT INTERROGATE_PYTHON_INTERFACE) + return() +endif() + +add_executable(run_pytest main.c) +target_link_libraries(run_pytest panda) +target_link_libraries(run_pytest Python::Python) + +# Note, we do NOT test for pytest before adding this test. If the user doesn't +# have pytest, we'd like for the tests to fail. + +# In the Coverage configuration, we also require pytest-cov + +# To prevent an empty argument from being passed in in non-Coverage builds, +# which will sometimes cause pytest to read all tests in the current directory, +# substitute a nonsensical argument that will be ignored instead +add_test(NAME pytest COMMAND run_pytest tests $,--cov=.,--ignore=nonexistent> + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") + +set_tests_properties(pytest PROPERTIES ENVIRONMENT "PYTHONPATH=${PANDA_OUTPUT_DIR}")