"attempt to write a readonly database" with BrowserTestBase Functional tests I have a functional test that is currently empty. I run it with the following command;
php core/scripts/run-tests.sh --sqlite /db/drupal.sqlite --php /usr/local/bin/php --verbose --directory modules/custom/

I have tried with and without the --sqlite command, as well as trying a non-existant file like tmpfs/drupal.sqlite, but I always get the same error:


Drupal\Tests\answers\Functional\AnswersTest::testAddContentPage
Exception: Drupal\Core\Database\DatabaseExceptionWrapper:
SQLSTATE[HY000]: General error: 8 attempt to write a readonly
database:


From that error I have gathered that the issue is that the user doesn't have write-access to the database, but without knowing where the database file is I'm not sure how to check this. I tried settings the permissions on /db/drupal.sqlite to 777 but this didn't help either.
I don't quite understand why this fixes the problem, but in my case the issue was caused by my executing the core/scripts/run-tests.sh script as root. By running it as www-data instead the issue went away.
I can only assume that the sqlite DB gets created by root and then the script switches itself over to www-data and can't access the DB anymore.