我试图在Windows上运行带有Tox的Python测试,其环境变量如下:
set APP=c:\path\to\app\n-starting-folder\app.apk & tox -- report.xml tests/someTest.py
在setUp()
方法中,我从环境变量中检索值:
capabilities = {}
capabilities['app'] = os.getenv('APP')
这给了我路径错误的错误:
error: Failed to start an Appium session, err was: Error: Bad app: c:\path\to\app\n-starting-folder\app.apk . App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Using local app, but didn't end in .zip, .ipa or .apk
但是如果我将(完全相同的)路径直接放入setUp()
方法作为原始字符串文字,那么没有错误:
capabilities['app']=r'c:\path\to\app\n-starting-folder\app.apk'
所以我的问题是:为什么来自环境变量的值会以某种方式被破坏?我怀疑这是因为路径中有"\n"
,但我不知道如何正确地逃脱它。