I'm trying to run elpy's C-c C-t to do elpy-test on a python test_x.py file I have opened on a remote machine with TRAMP.

Some parameters:

  • There is a python virtual env in the (remote machine's) directory, ~/myproject/env/default/
  • I want to run the tests relative to the (remote machine's) project root ~/myproject/
  • The PYTHONPATH is set to the root directory, which is ~/myproject/

Locally, I run C-c C-t and this works like so:

-*- mode: compilation; default-directory: "~/myproject/test/integration/data/mymod/" -*-
Compilation started at Thu May 13 13:56:38

py.test --log-level\=DEBUG /home/user/myproject/test/integration/data/mymod/mod2/test_x.py\:\:test_y
================================================================================ test session starts =================================================================================
platform linux -- Python 3.7.3, pytest-5.4.3, py-1.10.0, pluggy-0.13.1 -- /env/default/bin/python
cachedir: .pytest_cache
rootdir: /home/user/myproject, inifile: pytest.ini
plugins: asyncio-0.14.0, flask-1.1.0, forked-1.2.0, xdist-1.33.0, requests-mock-1.8.0, typeguard-2.7.0
collected 1 item                                                                                                                                                                     

mod2/test_x.py::test_y SKIPPED                                                                                                    [100%]

============================================================================= slowest 10 test durations ==============================================================================
0.00s setup    test/integration/data/mymod/mod2/test_x.py::test_y
0.00s teardown test/integration/data/mymod/mod2/test_x.py::test_y
================================================================================= 1 skipped in 2.05s =================================================================================

Compilation finished at Thu May 13 13:56:41

This looks good. This is exactly what I want to see.

However, when I remotely open the same file, and expect it to run on the remote machine via TRAMP, picking up the remote environment:

-*- mode: compilation; default-directory: #("/ssh:remote:/home/user/myproject/test/integration/data/mymod/" 1 4 (helm-ff-file t) 5 13 (helm-ff-file t)) -*-
Compilation started at Thu May 13 14:00:37

py.test --log-level\=DEBUG /ssh\:remote\:/home/user/myproject/test/integration/data/mymod/mod2/test_x.py\:\:test_y
/bin/sh: 2: py.test: not found

Compilation exited abnormally with code 127 at Thu May 13 14:00:37

Some things I notice:

  • The default directory looks mostly correct AFAICT, but I'm not sure what the #() is doing.
  • It's not clear to me why py.test is not found.
  • I don't see elpy listing any of that other stuff, like cachedir or platform---is it not configured at all?
  • Is there a variable I need to set either within emacs, orperhaps an environment variable, etc., so that when executed remotely, I can pick up the local environments?

Additionally, I have a .dir-locals.el in the root where I can set these as needed, if they are location-specific.

What can I change so I can run my tests with elpy over a tramp ssh session successfully?

1 Answer 1


I have no knowledge about elpy and the like. However, some observations:

  • py.test is not found because its location is not mentioned in the remote $PATH

  • The call of py.test comes with a remote file name /ssh\:remote\:/home/.... This looks wrong.

I recommend to contact the author(s) of elpy whether it is prepared for remote activation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.