Thanks to the helpful comments, I conclude: Yes it can, with a bit of help.
- you need to define
CIVICRM_CMSDIR in your code
- you need set
CIVICRM_SETTINGS as an environment var
As far as I can work out,
civicrm.settings.php before it sources
wp-config.php. So if, like me, you have config set in
civicrm.settings.php that depends on constants defined in
wp-config.php you'll have to find a solution for that (e.g. use
if (defined('...')) or put them all in a separate file and
Then you need something like this in your
define('CIVICRM_CMSDIR', __DIR__ . '/wp');
Basically CiviCRM is going to expect to find
wp-includes inside that directory, so adjust as you need to.
You don't need to call
cv from within any particular directory, according to my tests.
You need to set the environment variable
CIVICRM_SETTINGS to point to the
civicrm.settings.php file. This can be a relative or absolute path.
I was then able to get cv to run, e.g. to use the API. Now if only I could get my tests to run....!