Vagrant won't run nosetests under ssh -c

175 views Asked by At

I wanted to write a command to ssh into vagrant, change the current working directory, and then run nosetests.

I found in the documentation for vagrant that this could be done with vagrant ssh -c COMMAND

http://docs.vagrantup.com/v2/cli/ssh.html

The problem is I'm getting different results if I run nose through -c or manually after SSH.

Command:

vagrant ssh -c 'pwd && cd core && pwd && nosetests -x --failed' web

Output:

/web
/web/core

----------------------------------------------------------------------
Ran 0 tests in 4.784s

OK
Connection to 127.0.0.1 closed.

Commands:

vagrant ssh web

/web$ pwd && cd core && pwd && nosetests -x --failed

Output

/web                                                     
/web/core                                                
.........................................................
.........................................................
.........................................................
.........................................................
<snip>
...............................                          
---------------------------------------------------------

Ran 1399 tests in 180.325s

I don't understand why it makes a difference.

2

There are 2 answers

2
AudioBubble On

The first ssh session is not a terminal session. If you try ssh -t instead of vagrant ssh -c, likely the outputs will be the same. A command like the following should give output comparable to what you get locally:

ssh -t <username>@<ip-of-vagrant-machine> -p <vagrant-vm-ssh-port> 'pwd && cd core && pwd && nosetests -x --failed'

The default for username and password on vagrant machines is both "vagrant", the ssh-port and IP to ssh into are shown during the provisioning of the vagrant machine with vagrant up. If you prefer public key ssh login vagrant also can point you to the location of the ssh public key.

Depending on where you want to run nose on your vm you will have to adjust the cd command above, it seems that the vagrant ssh wrapper automatically moved you to /web on the VM.

If you just worry about wether the results of the tests will differ because of the visual difference: No, they shouldn't, the reason is just that on a non-interactive terminal nose displays the results in a different manner.

0
K Engle On

I was able to resolve this issue by running:

vagrant ssh -c 'cd core && nosetests -x --failed --exe' web

I'm not sure why this made a difference on my box.