You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What would you like to know?.
How to control the current working directory of the launched process?
Additional context
When using pytest-xprocess to launch a server process I notice that it is launched in a different directory:
<test_root>/.pytest_cache/d/.xprocess/<test_fixture_name>
I want the freedom to change that, because my poc server is unfortunately relying on local files.
The text was updated successfully, but these errors were encountered:
# Reference https://pytest-xprocess.readthedocs.io/en/latest/importpytest, os, pyfromxprocessimportXProcess, ProcessStarter@pytest.fixture(scope="session")defmyxprocess(request):
rootdir=py._path.local.LocalPath(os.environ['MY_WORKING_DIR'])
withXProcess(request.config, rootdir) asxproc:
request.config._xprocess=xprocyieldxproc@pytest.fixturedefmyserver(myxprocess):
classStarter(ProcessStarter):
pattern="Running Dispatch Server on port"args= ['myserver', '--profile']
logfile=myxprocess.ensure("", Starter) # Notice that the empty string is key here (nasty)yieldmyxprocess.getinfo("").terminate() # Notice that the empty string is key here (nasty)
Normally you would just customize process initialization using popen_kwargs as showed in our docs by setting cwd (check official Popen docs for details on this). But this will not work for cwd (specifically) since it's being used internally for setting up xProcessInfo.controldir where logs and PID files will be kept for process management.
I'll go ahead and mark it as a potential feature to be looked into in the future since it seems to be convenient to have. If anyone feels like tackling this, just let me know by commenting here and I'll be happy to review a PR.
@bryanloz-xilinx I couldn't make your work for me, but thanks for highlighting the problem here. I found a slightly cleaner workaround: spawn a new bash process with the command, e.g. instead of args = ['myserver', '--profile'], use args = ["bash", "-c", 'cd ../../../../ && myserver --profile']
What would you like to know?.
How to control the current working directory of the launched process?
Additional context
When using pytest-xprocess to launch a server process I notice that it is launched in a different directory:
<test_root>/.pytest_cache/d/.xprocess/<test_fixture_name>
I want the freedom to change that, because my poc server is unfortunately relying on local files.
The text was updated successfully, but these errors were encountered: