From 1ca4e57611388c9e7fc38431230f19a7e03f6cea Mon Sep 17 00:00:00 2001 From: Daniel Baston Date: Fri, 9 Feb 2024 11:37:57 -0500 Subject: [PATCH] autotest: run Python tests directly from source tree --- .github/workflows/alpine_32bit/test.sh | 9 +++++---- .github/workflows/asan/test.sh | 8 +++++--- .github/workflows/benchmarks/test.sh | 2 +- .github/workflows/coverage/test.sh | 9 +++++---- .github/workflows/ubuntu_22.04/test.sh | 19 ++++++++++--------- autotest/CMakeLists.txt | 26 ++++---------------------- 6 files changed, 30 insertions(+), 43 deletions(-) diff --git a/.github/workflows/alpine_32bit/test.sh b/.github/workflows/alpine_32bit/test.sh index 65f5b11fb26d..21a7b98d8f6d 100755 --- a/.github/workflows/alpine_32bit/test.sh +++ b/.github/workflows/alpine_32bit/test.sh @@ -4,7 +4,8 @@ set -e . ../scripts/setdevenv.sh -export PYTEST="python3 -m pytest -vv -p no:sugar --color=no" +export PYTEST="python3 -m pytest -c pytest.ini -vv -p no:sugar --color=no" +TEST_DIR=${GDAL_SOURCE_DIR:=..}/autotest make quicktest @@ -20,11 +21,11 @@ PYTEST_SKIP="gdrivers/jp2openjpeg.py $PYTEST_SKIP" # Failures for the following tests. See https://github.com/OSGeo/gdal/runs/1425843044 # depends on tiff_ovr.py that is going to be removed below -(cd autotest && $PYTEST utilities/test_gdaladdo.py) +(cd autotest && $PYTEST ${TEST_DIR}/utilities/test_gdaladdo.py) PYTEST_SKIP="autotest/utilities/test_gdaladdo.py $PYTEST_SKIP" for i in $PYTEST_XFAIL ; do - (cd autotest && $PYTEST $i || echo "Ignoring failure") + (cd autotest && $PYTEST ${TEST_DIR}/$i || echo "Ignoring failure") done -(cd autotest && $PYTEST $(echo " $PYTEST_SKIP $PYTEST_XFAIL" | sed -r 's/[[:space:]]+/ --ignore=/g')) +(cd autotest && $PYTEST ${TEST_DIR} $(echo " $PYTEST_SKIP $PYTEST_XFAIL" | sed -r 's/[[:space:]]+/ --ignore=/g')) diff --git a/.github/workflows/asan/test.sh b/.github/workflows/asan/test.sh index 2458b7455dc9..cca7c3b017b9 100755 --- a/.github/workflows/asan/test.sh +++ b/.github/workflows/asan/test.sh @@ -12,7 +12,9 @@ export LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so) export ASAN_OPTIONS=allocator_may_return_null=1:symbolize=1:suppressions=$PWD/../autotest/asan_suppressions.txt export LSAN_OPTIONS=detect_leaks=1,print_suppressions=0,suppressions=$PWD/../autotest/lsan_suppressions.txt -gdalinfo autotest/gcore/data/byte.tif +TEST_DIR=${GDAL_SOURCE_DIR:=..}/autotest + +gdalinfo ${TEST_DIR}/gcore/data/byte.tif python3 -c "from osgeo import gdal; print('yes')" cd autotest @@ -26,7 +28,7 @@ cd autotest echo "#!/bin/sh" > pytest_wrapper.sh echo 'ARGS="$*"' >> pytest_wrapper.sh -echo "python3 -m pytest --capture=no -ra -vv -p no:sugar --color=no -o console_output_style=classic \${ARGS} 2>&1" >> pytest_wrapper.sh +echo "python3 -m pytest -c pytest.ini --capture=no -ra -vv -p no:sugar --color=no -o console_output_style=classic \${ARGS} 2>&1" >> pytest_wrapper.sh cat pytest_wrapper.sh chmod +x pytest_wrapper.sh @@ -34,7 +36,7 @@ chmod +x pytest_wrapper.sh # That turns out to be what we want here though, since we want # to not fail when the address sanitizer finds errors. # So we tee the output to a file and grep it to discover if the tests failed. -find -L \ +find ${TEST_DIR} \ ogr gcore gdrivers osr alg gnm utilities pyscripts \ -name '*.py' \ ! -name netcdf_cfchecks.py \ diff --git a/.github/workflows/benchmarks/test.sh b/.github/workflows/benchmarks/test.sh index 3f5332d2e0b4..d86ac724a0f5 100755 --- a/.github/workflows/benchmarks/test.sh +++ b/.github/workflows/benchmarks/test.sh @@ -24,4 +24,4 @@ BENCHMARK_COMPARE_OPTIONS=( "--benchmark-compare=0001_ref" \ ) -(source ${GDAL_SOURCE_DIR:=..}/scripts/setdevenv.sh; pytest autotest/benchmark "${BENCHMARK_OPTIONS[@]}" "${BENCHMARK_COMPARE_OPTIONS[@]}" --capture=no -ra -vv || (echo "Retrying..."; pytest autotest/benchmark "${BENCHMARK_OPTIONS[@]}" "${BENCHMARK_COMPARE_OPTIONS[@]}" --capture=no -ra -vv)) +(source ${GDAL_SOURCE_DIR:=..}/scripts/setdevenv.sh; pytest ${GDAL_SOURCE_DIR:=..}/autotest/benchmark "${BENCHMARK_OPTIONS[@]}" "${BENCHMARK_COMPARE_OPTIONS[@]}" --capture=no -ra -vv || (echo "Retrying..."; pytest ${GDAL_SOURCE_DIR:=..}/autotest/benchmark "${BENCHMARK_OPTIONS[@]}" "${BENCHMARK_COMPARE_OPTIONS[@]}" --capture=no -ra -vv)) diff --git a/.github/workflows/coverage/test.sh b/.github/workflows/coverage/test.sh index 2275e8fb1305..0b5a0e23f488 100755 --- a/.github/workflows/coverage/test.sh +++ b/.github/workflows/coverage/test.sh @@ -12,15 +12,16 @@ export PYTEST="python3 -m pytest -vv -p no:sugar --color=no" . ../scripts/setdevenv.sh IP=host.docker.internal +TEST_DIR=${GDAL_SOURCE_DIR:=..}/autotest # MySQL 8 -(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33060,host=$IP $PYTEST ogr/ogr_mysql.py) +(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33060,host=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mysql.py) # MariaDB 10.3.9 -(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33061,host=$IP $PYTEST ogr/ogr_mysql.py) +(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33061,host=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mysql.py) # PostGIS tests -(cd autotest && OGR_PG_CONNECTION_STRING="host=$IP port=25432 dbname=autotest user=docker password=docker" $PYTEST --capture=no -ra ogr/ogr_pg.py) -(cd autotest && PGHOST="$IP" PGPORT=25432 PGUSER=docker PGPASSWORD=docker $PYTEST --capture=no -ra gdrivers/postgisraster.py) +(cd autotest && OGR_PG_CONNECTION_STRING="host=$IP port=25432 dbname=autotest user=docker password=docker" $PYTEST --capture=no -ra ${TEST_DIR}/ogr/ogr_pg.py) +(cd autotest && PGHOST="$IP" PGPORT=25432 PGUSER=docker PGPASSWORD=docker $PYTEST --capture=no -ra ${TEST_DIR}/gdrivers/postgisraster.py) # Generate coverage report lcov --directory . --capture --output-file gdal.info 2>/dev/null diff --git a/.github/workflows/ubuntu_22.04/test.sh b/.github/workflows/ubuntu_22.04/test.sh index 5addcb8694eb..b493f3b70493 100755 --- a/.github/workflows/ubuntu_22.04/test.sh +++ b/.github/workflows/ubuntu_22.04/test.sh @@ -4,30 +4,31 @@ set -e . ../scripts/setdevenv.sh -export PYTEST="python3 -m pytest -vv -p no:sugar --color=no" +export PYTEST="python3 -m pytest -c pytest.ini -vv -p no:sugar --color=no" # Run C++ tests make quicktest IP=host.docker.internal +TEST_DIR=${GDAL_SOURCE_DIR:=..}/autotest # Test /vsiaz/ against the Azurite simulator export AZURITE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://${IP}:10000/devstoreaccount1;" AZURE_STORAGE_CONNECTION_STRING=${AZURITE_STORAGE_CONNECTION_STRING} python3 -c "from osgeo import gdal; import sys; sys.exit(gdal.Mkdir('/vsiaz/mycontainer', 0o755))" -(cd autotest && AZURE_STORAGE_CONNECTION_STRING=${AZURITE_STORAGE_CONNECTION_STRING} AZ_RESOURCE=mycontainer $PYTEST gcore/vsiaz_real_instance_manual.py) +(cd autotest && AZURE_STORAGE_CONNECTION_STRING=${AZURITE_STORAGE_CONNECTION_STRING} AZ_RESOURCE=mycontainer $PYTEST ${TEST_DIR}/gcore/vsiaz_real_instance_manual.py) # MySQL 8 -(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33060,host=$IP $PYTEST ogr/ogr_mysql.py) +(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33060,host=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mysql.py) # MariaDB 10.3.9 -(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33061,host=$IP $PYTEST ogr/ogr_mysql.py) +(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33061,host=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mysql.py) # PostGIS tests -(cd autotest && OGR_PG_CONNECTION_STRING="host=$IP port=25432 dbname=autotest user=docker password=docker" $PYTEST --capture=no -ra ogr/ogr_pg.py) -(cd autotest && PGHOST="$IP" PGPORT=25432 PGUSER=docker PGPASSWORD=docker $PYTEST --capture=no -ra gdrivers/postgisraster.py) +(cd autotest && OGR_PG_CONNECTION_STRING="host=$IP port=25432 dbname=autotest user=docker password=docker" $PYTEST --capture=no -ra ${TEST_DIR}/ogr/ogr_pg.py) +(cd autotest && PGHOST="$IP" PGPORT=25432 PGUSER=docker PGPASSWORD=docker $PYTEST --capture=no -ra ${TEST_DIR}/gdrivers/postgisraster.py) # MongoDB v3 -(cd autotest && MONGODBV3_TEST_PORT=27018 MONGODBV3_TEST_HOST=$IP $PYTEST ogr/ogr_mongodbv3.py) +(cd autotest && MONGODBV3_TEST_PORT=27018 MONGODBV3_TEST_HOST=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mongodbv3.py) -(cd autotest && OGR_MSSQL_CONNECTION_STRING="MSSQL:server=$IP;database=TestDB;driver=ODBC Driver 17 for SQL Server;UID=SA;PWD=DummyPassw0rd" $PYTEST ogr/ogr_mssqlspatial.py) +(cd autotest && OGR_MSSQL_CONNECTION_STRING="MSSQL:server=$IP;database=TestDB;driver=ODBC Driver 17 for SQL Server;UID=SA;PWD=DummyPassw0rd" $PYTEST ${TEST_DIR}/ogr/ogr_mssqlspatial.py) -(cd autotest && $PYTEST) +(cd autotest && $PYTEST ${TEST_DIR}) diff --git a/autotest/CMakeLists.txt b/autotest/CMakeLists.txt index d28a06d7ce59..728a3c0bb28b 100644 --- a/autotest/CMakeLists.txt +++ b/autotest/CMakeLists.txt @@ -69,19 +69,8 @@ function (symlink_or_copy source destination) endif () endfunction () - symlink_or_copy(${CMAKE_CURRENT_SOURCE_DIR}/conftest.py ${CMAKE_CURRENT_BINARY_DIR}/conftest.py) symlink_or_copy(${CMAKE_CURRENT_SOURCE_DIR}/run_slow_tests.sh ${CMAKE_CURRENT_BINARY_DIR}/run_slow_tests.sh) - if (NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") - foreach (subdir IN ITEMS pymod proj_grids cpp/data) - if (SKIP_COPYING_AUTOTEST_SUBDIRS) - message(STATUS "Skipping copying ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}") - else () - symlink_or_copy(${CMAKE_CURRENT_SOURCE_DIR}/${subdir} ${CMAKE_CURRENT_BINARY_DIR}/${subdir}) - endif () - endforeach () - endif() - foreach ( tgt IN ITEMS ogr @@ -94,20 +83,13 @@ endfunction () utilities benchmark slow_tests) - if (NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") - if (SKIP_COPYING_AUTOTEST_SUBDIRS) - message(STATUS "Skipping copying ${CMAKE_CURRENT_SOURCE_DIR}/${tgt}") - else () - symlink_or_copy(${CMAKE_CURRENT_SOURCE_DIR}/${tgt} ${CMAKE_CURRENT_BINARY_DIR}/${tgt}) - endif () - endif() add_custom_target( autotest_${tgt} COMMAND ${CMAKE_COMMAND} -E env ${PYTHON_RUN_ENV} ${Python_EXECUTABLE} -m pytest -c - ${CMAKE_CURRENT_BINARY_DIR}/pytest.ini ${tgt} + ${CMAKE_CURRENT_LIST_DIR}/pytest.ini ${CMAKE_CURRENT_LIST_DIR}/${tgt} DEPENDS ${GDAL_LIB_TARGET_NAME} gdalapps python_binding) - add_test(NAME autotest_${tgt} COMMAND ${Python_EXECUTABLE} -m pytest -c ${CMAKE_CURRENT_BINARY_DIR}/pytest.ini - ${tgt}) + add_test(NAME autotest_${tgt} + COMMAND ${Python_EXECUTABLE} -m pytest -c ${CMAKE_CURRENT_BINARY_DIR}/pytest.ini ${CMAKE_CURRENT_LIST_DIR}/${tgt}) set_property(TEST autotest_${tgt} PROPERTY ENVIRONMENT "${PYTHON_RUN_ENV}") endforeach () add_custom_target( @@ -175,7 +157,7 @@ int main(int argc, char **argv) { COMMAND ${CMAKE_COMMAND} -E env ${PYTHON_RUN_ENV} $ -c ${CMAKE_CURRENT_BINARY_DIR}/pytest.ini DEPENDS ${GDAL_LIB_TARGET_NAME} gdalapps python_binding pytest_runner - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) endif () endif ()