From fd3731ebe6217285547757cd2a1508da5217deb2 Mon Sep 17 00:00:00 2001 From: Kai Kratz Date: Mon, 14 Oct 2024 11:35:34 +0200 Subject: [PATCH] Address pytest root dir --- CMakeLists.txt | 16 +++++++++++++--- cmake/run_pytest.sh.in | 4 ++-- pyproject.toml | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 pyproject.toml diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a3f480..11002b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ if (HAVE_GRIBJUMP_LOCAL_EXTRACT) endif() # python api test are currently by default disabled because we cannot run them in the ci -ecbuild_add_option( +ecbuild_add_option( FEATURE PYTHON_API_TESTS DEFAULT OFF DESCRIPTION "Will execute python tests against pygribjump / libgribjump") @@ -90,10 +90,20 @@ if(HAVE_PYTHON_API_TESTS) find_python_module(setuptools) find_python_module(findlibs) - set(FDB5_DIR "${fdb5_DIR}/../../..") + # Prepare to export FDB5_DIR so that findlibs does find our depenant libfdb for pyfdb + # In case we build gribjump standalone, this code relies on the location + # provided by the find module, i.e. fdb5_DIR. + # If this code is build as a bundle, aka a subproject we need to point + # findlib to the folder containing the CMAKE_LIBRARY_OUTPUT_DIRECTORY + if(fdb5_DIR) + set(FDB5_DIR "${fdb5_DIR}/../../..") + else() + set(FDB5_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/..") + endif() + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run_pytest.sh.in - ${CMAKE_BINARY_DIR}/run_pytest.sh + ${CMAKE_CURRENT_BINARY_DIR}/run_pytest.sh @ONLY ) diff --git a/cmake/run_pytest.sh.in b/cmake/run_pytest.sh.in index 57d06b9..c93e611 100755 --- a/cmake/run_pytest.sh.in +++ b/cmake/run_pytest.sh.in @@ -2,7 +2,7 @@ export GRIBJUMP_HOME="@CMAKE_BINARY_DIR@" export FDB5_DIR="@FDB5_DIR@" -export PYTHONPATH="${PYTHONPATH}:@CMAKE_SOURCE_DIR@/pygribjump/src" +export PYTHONPATH="${PYTHONPATH}:@CMAKE_CURRENT_SOURCE_DIR@/pygribjump/src" -@Python_EXECUTABLE@ -m pytest @CMAKE_SOURCE_DIR@ --basetemp="@CMAKE_BINARY_DIR@/test-results" "$@" +@Python_EXECUTABLE@ -m pytest @CMAKE_CURRENT_SOURCE_DIR@ --basetemp="@CMAKE_CURRENT_BINARY_DIR@/test-results" "$@" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..496e120 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "-vv -s" +testpaths = [ + "pygribjump/tests" +]