[英]Setting $PATH via a command with tox
Currently using tox
to test a python package, and using a python library ( chromedriver-binary
) to install chromedriver
. 当前使用
tox
测试python软件包,并使用python库( chromedriver-binary
)安装chromedriver
。
This library creates a script ( chromedriver-path
) which when called outputs the PATH where chromedriver
is installed. 这个程式库会建立一个
chromedriver-path
码( chromedriver-path
),执行时会输出chromedriver
的安装路径。 The usual way to use this is to run: 使用此方法的通常方法是运行:
export PATH=$PATH:`chromedriver-path`
I've tried the following without success in tox.ini
我在
tox.ini
尝试了以下方法但未成功
setenv=
PATH = {env:PATH}{:}`chromedriver-path`
This errors as expected: 出现以下错误:
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
FileNotFoundError:[错误2]没有这样的文件或目录:'chromedriver':'chromedriver'
Implying that the setenv command is never called/run. 意味着永远不会调用/运行setenv命令。
commands=
export PATH=$PATH:`chromedriver-path
This fails with: 失败的原因是:
ERROR: InvocationError for command could not find executable export
错误:命令的InvocationError找不到可执行文件导出
How do I make this work? 我该如何工作?
Commands can't change their parent processes' environment variables, and thus can't change the environment variables of subsequent commands launched by forking that parent; 命令不能更改其父进程的环境变量,因此也不能更改通过分叉该父进程而启动的后续命令的环境变量。 they can only set environment variables for themselves or their own children.
他们只能为自己或自己的孩子设置环境变量。
If you were able to collect the output of chromedriver-path
before starting tox
, this would be moot. 如果您能够在开始
tox
之前收集chromedriver-path
的输出,那将是没有意义的。 If it's only available in an environment tox itself creates, then things get a bit more interesting. 如果只能在tox本身创建的环境中使用,那么事情会变得更加有趣。
One approach you can follow is to wrap the commands that need this path entry in a shim that adds it. 您可以采用的一种方法是将需要此路径条目的命令包装在添加了它的垫片中。 Consider changing:
考虑更改:
commands=
py test ...
to: 至:
commands=
sh -c 'PATH=$PATH:$(chromedrive-path); exec "$@"' _ py test ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.