Docs say (see http://nginx.org/r/proxy_pass):
A server name, its port and the passed URI can also be specified using variables ...
That is, if you use variables, the passed URI is expected to be specified, not a replacement URI part. This behaviour is required for original use case variables support in proxy_pass
was added - to allow requests to any resource explicitly specified using variables.
While this may not be very natural behaviour for some other use cases like the one you describe, it's how it's expected to work and documented. Improving docs to be more explicit may make sense though.
Note well that in this particular case, when you don't need to change anything in the URI, it should be better to just use a server name, without an URI part. In this case nginx is smart enough to use original request URI regardless of whether you use variable or not:
location /test/ {
set $upstream_var upstream;
proxy_pass http://$upstream_var;
}