Why is my alias "NULL" in a test? I am using Drupal 7, I have Pathauto enabled, and my user has permissions to create new aliases.

When I manually create a node, uncheck the checkbox for automatic alias generation, and enter a custom alias (e.g. 'qwerty'), I can use drupal_lookup_path() to return the alias. So

$path = drupal_lookup_path('node/' . $node-&gt;nid);


gives $path a value of 'qwerty'. 

However, when I create a node in simpletest with the code 

$edit = array(
  'title' =&gt; 'asdf',
  'path[alias]' =&gt; 'qwerty',
);
$this-&gt;drupalPost("node/add/{$this-&gt;content_type}", $edit, t('Save'));


and then 

$path = drupal_lookup_path('node/' . $node-&gt;nid);


$path has a value of 'NULL', even when the alias is functioning, e.g. when

$this-&gt;drupalGet('qwerty');


returns a 200 status.

Why is drupal_lookup_path() failing to find my alias only when called from a test?
I tracked this down to the fact that current_path(), which returns path/to/content in the browser, instead returns batch when called from within Simpletest. 

Since drupal_lookup_path() uses the output of current_path() to generate the $cache[map] variable that it uses to find and store the path alias, this prevents drupal_lookup_path() from working in tests.

I have filed this as an issue on d.o.