Python - 从终端执行时错误的目录

时间:2015-03-20 19:21:19

标签: python-2.7 terminal environment-variables pycharm python-unittest

如果我从IDE运行dir路径没问题,但是当我从termianl执行时,我正在例外:

代码:

def __init__(self):
        dir = os.path.abspath(os.path.join(__file__, os.pardir))
        self.LOCATOR_FILE_PATH = dir+'/locators/locator_'+self.get_class_name_lower()+'.json'
        with open(self.LOCATOR_FILE_PATH) as json_data:

例外:

E
======================================================================
ERROR: test_verify_page (test_verify_page.TestVerifyPage)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_verify_page.py", line 9, in test_verify_page
    sign_inPage = SignInPage()
  File "C:\Python27\lib\site-packages\page_objects\sign_in_page.py", line 47, in __init__
    with open(self.LOCATOR_FILE_PATH) as json_data:
IOError: [Errno 2] No such file or directory: 'C:\\Python27\\lib\\site-packages\\page_objects/locators/locator_signinpage.json'

----------------------------------------------------------------------
Ran 1 test in 13.189s

FAILED (errors=1)

放置文件的真实路径是:

“C:\ MY_PROJECT \ page_objects \定位器\ locator_signinpage.json'

我检查了python控制台中的设置,但我无法解决这个问题。

0 个答案:

没有答案