From 5193d3f9494c977ac4694a1fc6fb0570ce6e92a7 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 10 Jun 2020 01:09:33 +0200 Subject: tests: Add infrastructure to run Python unit tests - Add UHD_ADD_PYTEST() CMake macro - Add CMake code to tests/CMakeLists.txt to auto-run all registered Python unit tests - Add a token unit test (it replicates parts of ranges_test.cpp) The way Python-based unit tests are implemented in UHD is that they can import uhd, and then operate on the module as usual. Writing unit tests in Python instead of C++ can have multiple advantages: - If they test PyBind-wrapped C++ code, they can test both the binding and the underlying C++ code at once - Writing unit tests in Python may be more concise --- host/cmake/Modules/UHDUnitTest.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'host/cmake') diff --git a/host/cmake/Modules/UHDUnitTest.cmake b/host/cmake/Modules/UHDUnitTest.cmake index 9a71ca2aa..f1f52addc 100644 --- a/host/cmake/Modules/UHDUnitTest.cmake +++ b/host/cmake/Modules/UHDUnitTest.cmake @@ -104,3 +104,15 @@ function(UHD_ADD_TEST test_name) endif(WIN32) endfunction(UHD_ADD_TEST) + +######################################################################## +# Add a Python unit test +######################################################################## +function(UHD_ADD_PYTEST test_name) + add_test(NAME ${test_name} + COMMAND ${RUNTIME_PYTHON_EXECUTABLE} -m unittest discover + -s ${CMAKE_CURRENT_SOURCE_DIR} + -p "${test_name}.*" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/python" + ) +endfunction(UHD_ADD_PYTEST) -- cgit v1.2.3