Skip to content

Commit 06ba598

Browse files
schlesseraclaude
andcommitted
Do not require the test database to exist before a run
The database check before a run required the test database to exist, while the scenarios drop it themselves. After a run in parallel workers, the rerun of the failed scenarios therefore usually switched to SQLite, even when testing against MySQL. Check that the test user may create the database instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 79d8dda commit 06ba598

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎bin/run-behat-tests‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ else
7878

7979
DBNAME=${WP_CLI_TEST_DBNAME:-wp_cli_test}
8080

81-
# We need to test the connection.
82-
# Let's try to connect to the specific test database.
83-
if ! ${DB_CLIENT} ${HOST_STRING} --user="${USER}" ${PASSWORD_ARG} --execute="USE \`${DBNAME}\`;" 2>/dev/null; then
81+
# We need to test the connection, and that the test user may create the test database.
82+
# The database itself does not need to exist, as the scenarios drop and create it, which
83+
# is also why a rerun after a run in parallel workers usually finds it missing.
84+
if ! ${DB_CLIENT} ${HOST_STRING} --user="${USER}" ${PASSWORD_ARG} --execute="CREATE DATABASE IF NOT EXISTS \`${DBNAME}\`;" 2>/dev/null; then
8485
echo "Warning: Could not connect to the MySQL/MariaDB database."
8586
echo "Please make sure the database is running and run 'composer prepare-tests' once to set it up."
8687
echo "The tests will continue to be run, but with WP_CLI_TEST_DBTYPE=sqlite."

0 commit comments

Comments
 (0)