Test environment
How the test database and Flask app are configured when tests run.
Table of contents
How it works
SPLENT_APPidentifies the active productget_create_app_in_testing_mode()callscreate_app("testing")- Flask picks up
TestingConfig
class TestingConfig(Config):
TESTING = True
WTF_CSRF_ENABLED = False
def __init__(self):
super().__init__()
self.SQLALCHEMY_DATABASE_URI = _build_db_uri(
"MARIADB_TEST_DATABASE", "default_test_db"
)
Environment variables
| Variable | Default | Purpose |
|---|---|---|
MARIADB_USER |
default_user |
Database username |
MARIADB_PASSWORD |
default_password |
Database password |
MARIADB_HOSTNAME |
localhost |
Database host |
MARIADB_TEST_DATABASE |
default_test_db |
Test database name |
Tests always run inside the CLI container. The test database is separate from dev.
feature:testvalidates thatSQLALCHEMY_DATABASE_URIcontainstestbefore running.
E2E and load variables
E2E and load tests run against a live server and read their own variables.
| Variable | Default | Purpose |
|---|---|---|
SELENIUM_GRID_URL |
unset | Attach the Selenium driver to this grid hub instead of launching a local browser. |
SELENIUM_BROWSER |
chrome |
Browser for E2E tests, chrome or firefox. |
SELENIUM_TARGET_URL |
unset | Base URL for E2E tests. Required with a grid, since the browser container resolves the URL and localhost would point at itself. |
SPLENT_LOCUSTFILES |
unset | Comma-separated glob patterns that replace the Locust bootstrap’s default locustfile discovery. |
See E2E (Selenium) and Load (Locust) for details.
Production guard
If SPLENT_ENV=prod is detected (in the product’s .env or from the running web container), tests refuse to run.
Cannot run tests in production.
A production deployment is active.
Stop the deployment and start dev:
splent product:deploy --down
splent product:derive --dev
See also
- Fixtures. The test fixtures that create the app and reset the DB