Provide a sourceable shell script setting up test environment

Testing locally becomes as simple as (from build dir):

  . tests/env.sh
  python ${srcdir}/tests/src/python/test_provider_postgres.py
This commit is contained in:
Sandro Santilli 2024-06-22 08:27:12 +02:00
parent ec89b38853
commit e4ec6f0700
3 changed files with 36 additions and 0 deletions

View File

@ -6,6 +6,11 @@ if (ENABLE_TESTS)
endif()
add_subdirectory(code_layout)
configure_file(
"${CMAKE_SOURCE_DIR}/tests/env.sh.in"
"${CMAKE_BINARY_DIR}/tests/env.sh"
IMMEDIATE @ONLY)
endif()

View File

@ -130,6 +130,16 @@ with something like this (tweak $builddir and $srcdir as appropriate)
TestQgsVectorLayer.testOverwriteLayer
```
A convenient way to set all the variables used in the above snippet
automatically is by sourcing the tests/env.sh script in build dir,
for example:
```
source build/tests/env.sh
python ${srcdir}/tests/src/python/test_provider_postgres.py \
TestPyQgsPostgresProvider.testExtent
````
#### Running python tests in GDB
First find out the required environment variables by running the test outside

21
tests/env.sh.in Normal file
View File

@ -0,0 +1,21 @@
# Source this to configure environment in a way to make
# it easy to run python tests manually.
#
# See tests/README.md in source dir
#
_srcdir=@CMAKE_SOURCE_DIR@
_builddir=@CMAKE_BINARY_DIR@
if expr "${_builddir}" : "@" > /dev/null || test -z "${_builddir}" ||
expr "${_srcdir}" : "@" > /dev/null || test -z "${_srcdir}"
then
echo "This File, it wasn't generated properly." >&2
return 1
fi
export srcdir=${_srcdir}
export builddir=${_builddir}
export QGIS_PREFIX_PATH=${builddir}/output
export PYTHONPATH=${builddir}/output/python:$PYTHONPATH