Run the full test suite:
pytestRun individual test classes or methods:
pytest -k "TestExcelQuery"
pytest -k "test_get_queries_from_excel"Exclude database tests:
pytest -m "not dbtest"Run tests against specific databases:
pytest -m postgres
pytest -m mysql
pytest -m mssqlUse Docker Compose to start database services for tests:
-
Start the services:
docker-compose up -d
-
Wait for services to be healthy:
docker-compose ps
-
Run your tests. The default environment variables in
tests/conftest.pywork automatically:- PostgreSQL:
postgresql://postgres@localhost/ - MySQL:
mysql+pymysql://travis@/ - MS SQL Server:
mssql+pyodbc://SA:Password-123@localhost/
If needed, you can override with environment variables:
export POSTGRES_URL='postgresql://postgres@localhost/' export MYSQL_URL='mysql+pymysql://root@localhost/' export MSSQL_URL='mssql+pyodbc://SA:Password-123@localhost/'
- PostgreSQL:
-
Stop the services when done:
docker-compose down
To also remove the data volumes:
docker-compose down -v
For MS SQL Server tests, you need the ODBC Driver for SQL Server installed on your host system.
From learn.microsoft.com (source)
# Download the package to configure the Microsoft repo
curl -sSL -O https://packages.microsoft.com/config/debian/$(grep VERSION_ID /etc/os-release | cut -d '"' -f 2 | cut -d '.' -f 1)/packages-microsoft-prod.deb
# Install the package
sudo dpkg -i packages-microsoft-prod.deb
# Delete the file
rm packages-microsoft-prod.deb
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
odbcinst -q -d/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql18Running the integration tests requires API credentials from CommCare HQ
that have access to the corpora domain. The API key should only have
access to the corpora domain.
Set the credentials as environment variables:
export HQ_USERNAME=<username>
export HQ_API_KEY=<apikey>These are included as encrypted variables in the GitHub Actions configuration.