如何使用环境变量

kar*_*102 0 python

在终端中,我设置了www站点和路径以创建测试报告。

我设置: MY_URL=mysite:myport REPORTPA=./mypath/mysecondfolder/ pytest -s testFile.py --html=REPORTPA/report.html

我应该保存report.html,我尝试以下解决方案:

$REPORTPA/report.html or %REPORTPA/report.html

而且它用的不好。如何使用变量?

chr*_*ris 5

使用os.environ (docs),如下所示:

>>> import os
>>> reportpa = os.environ['REPORTPA']
>>> print(reportpa)
./mypath/mysecondfolder/
Run Code Online (Sandbox Code Playgroud)

  • 只要`x = y`在命令之前并且在同一行(如在OP的帖子中),就不需要导出。试试看:`REPORTPA =。/ mypath / mysecondfolder / python` (2认同)