Setting up a remote environment when using xdist

I am currently working on a project that includes tests that will run on a remote host (bash). Unfortunately, the remote python interpreter does not respect the available site packages (it is built-in: abaqus python (2.6)). However, using the PYTHONPATH variable allows you to specify local settings and make additional packages available. Therefore, on the remote computer, I simply add the appropriate line to my .bashrc file.

Unfortunately, when distributing tests using xdist, only bare bash is called, without any specific rcs profiles. Thus, the tests fail with some import errors, since the argparse, which pytest requires, is not available.

Is there a way to configure the remote host before it starts executing any pytest code (which requires argparse)? In other words, is there a way to add environment variables on nodes before starting pytest import?

I tried using appliances with session area and autouse=True , which (of course) did not work. Also, I tried something like

 # in conftest.py import sys def pytest_configure_node(): sys.path.insert(1, "/somepath/") print sys.path 

It looks like it is running on the remote host, but sys.path remains the host, and the argparse module still cannot be imported.

I run tests using

 py.test --tx ssh=user@server //python="abaqus613 python" -vs --dist=each --rsyncdir foo 

This starts the correct python interpreter (Python 2.6.2 for Abaqus 6.13-2), but with an error

 ImportError: No module named argparse 
+7
python
source share
2 answers

Finally, I realized a rather hacky, but reasonably working way. A number of commands can be specified in a python call, so I am the source of a script that sets up the environment before calling abaqus python.

The setup script (setup.sh) located on the remote computer looks like this:

 export PYTHONPATH=/path/to/libraries 

and now full challenge

 py.test --tx ssh=user@server //python="source setup.sh;abaqus613 python" -vs --dist=each --rsyncdir foo 

This way I get the necessary import working in abaqus python.

+1
source share

My plugin https://github.com/pytest-dev/pytest-cloud should help you

it automatically creates a python rsyncs virtual environment for slaves, one of the requirements is that your virtualenv folder must be inside the folder where the test folder is

after rsync it also activates the virtual environment, so that all your dependencies are there properly

+1
source share

All Articles