Fork this repo and commit your changes to the forked repo. From there make a Pull Request with your submission keeping the following in mind:
The CI pipeline in this repo runs a bunch of validation checks and code reformatting with pre-commit checks. If you don't install those checks in your clone of the repo, the code will likely not pass. To install the pre-commit tool in your clone run the following from your clone directory. This will force the checks before you can push.
pip install pre-commit==3.7.1
pre-commit install
The checks run automatically when you attempt to commit, but you can run them manually as well with the following:
pre-commit run --all-files
Before running tests, ensure you have:
- Docker installed and running (for automatic test database management)
- Test dependencies installed:
pip install -e ".[test]"orpip install -e ".[dev]"for all development dependencies
The docker Python package is required for the test framework to manage Docker containers automatically.
To create a test environment:
pip install -e ".[dev]" # All development dependencies (recommended)Or if you only need specific dependency groups:
pip install -e ".[test]" # Just testing dependencies
pip install -e ".[docs]" # Just documentation dependencies
pip install -e ".[build]" # Just build dependencies
pip install -e ".[examples]" # Just example/demo dependenciesThe test framework provides automatic Docker container management. When you run tests without setting SINGLESTOREDB_URL, the framework will:
- Automatically start a SingleStore Docker container (
ghcr.io/singlestore-labs/singlestoredb-dev) - Allocate dynamic ports to avoid conflicts (MySQL, Data API, Studio)
- Wait for the container to be ready
- Run all tests against the container
- Clean up the container after tests complete
# Run all tests (auto-starts Docker container)
pytest -v singlestoredb/tests
# Run with coverage
pytest -v --cov=singlestoredb --pyargs singlestoredb.tests
# Run single test file
pytest singlestoredb/tests/test_basics.py
# Run without management API tests
pytest -v -m 'not management' singlestoredb/testsThe SDK supports testing via SingleStore's Data API (port 9000) instead of the MySQL protocol (port 3306). This mode uses a dual-URL system:
SINGLESTOREDB_URL: Set to HTTP Data API endpoint (port 9000) for test operationsSINGLESTOREDB_INIT_DB_URL: Automatically set to MySQL endpoint (port 3306) for setup operations
Why dual URLs? Some setup operations like SET GLOBAL and USE database commands don't work over the HTTP Data API, so they're routed through the MySQL protocol automatically.
Enable HTTP Data API testing:
# Run tests via HTTP Data API
USE_DATA_API=1 pytest -v singlestoredb/testsKnown Limitations in HTTP Data API Mode:
USE databasecommand is not supported (some tests will be skipped)- Setup operations requiring
SET GLOBALare automatically routed to MySQL protocol
If you have a running SingleStore instance, you can test against it by setting SINGLESTOREDB_URL. The Docker container will not be started.
# Test against MySQL protocol
SINGLESTOREDB_URL=user:password@host:3306 pytest -v singlestoredb/tests
# Test against Data API
SINGLESTOREDB_INIT_DB_URL=user:password@host:3306 \
SINGLESTOREDB_URL=http://user:password@host:9000 \
pytest -v singlestoredb/testsWhen the test framework starts a Docker container automatically:
- Container name:
singlestoredb-test-{worker}-{uuid}(supports parallel test execution) - Port mappings:
- MySQL protocol: Random available port → Container port 3306
- Data API (HTTP): Random available port → Container port 9000
- Studio: Random available port → Container port 8080
- License: Uses
SINGLESTORE_LICENSEenvironment variable if set, otherwise runs without license - Cleanup: Container is automatically removed after tests complete
The following environment variables control test behavior:
-
SINGLESTOREDB_URL: Database connection URL. If not set, a Docker container is started automatically.- MySQL format:
user:password@host:3306 - HTTP format:
http://user:password@host:9000
- MySQL format:
-
USE_DATA_API: Set to1,true, oronto run tests via HTTP Data API instead of MySQL protocol.- Automatically sets up the dual-URL system
- Example:
USE_DATA_API=1 pytest -v singlestoredb/tests
-
SINGLESTOREDB_INIT_DB_URL: MySQL connection URL for setup operations (auto-set in HTTP Data API mode). Used for operations that require MySQL protocol even when testing via HTTP. -
SINGLESTORE_LICENSE: Optional license key for Docker container. If not provided, container runs without a license. -
SINGLESTOREDB_PURE_PYTHON: Set to1to disable C acceleration and test in pure Python mode. -
SINGLESTOREDB_MANAGEMENT_TOKEN: Management API token for testing management features (mark tests with@pytest.mark.management).
-
Test both protocols: Always run tests with both MySQL protocol and HTTP Data API before submitting:
pytest -v singlestoredb/tests USE_DATA_API=1 pytest -v singlestoredb/tests
-
Pure Python testing: Test without C acceleration to ensure compatibility:
SINGLESTOREDB_PURE_PYTHON=1 pytest -v singlestoredb/tests
-
Management API tests: These require a management token and are marked with
@pytest.mark.management.
# Standard workflow - test both protocols
pytest -v singlestoredb/tests
USE_DATA_API=1 pytest -v singlestoredb/tests
# Test single module with coverage
pytest -v --cov=singlestoredb.connection singlestoredb/tests/test_connection.py
# Test UDF functionality
pytest singlestoredb/tests/test_udf.py
# Test against specific server (skips Docker)
SINGLESTOREDB_URL=admin:pass@localhost:3306 pytest -v singlestoredb/tests
# Debug mode with verbose output
pytest -vv -s singlestoredb/tests/test_basics.py