rdb 5 дней назад
Родитель
Сommit
ebb556a866
2 измененных файлов с 23 добавлено и 11 удалено
  1. 3 11
      CMakeLists.txt
  2. 20 0
      tests/CMakeLists.txt

+ 3 - 11
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"
-    $<$<CONFIG:Coverage>:--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

+ 20 - 0
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 $<IF:$<CONFIG:Coverage>,--cov=.,--ignore=nonexistent>
+  WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
+
+set_tests_properties(pytest PROPERTIES ENVIRONMENT "PYTHONPATH=${PANDA_OUTPUT_DIR}")