2017-02-27 132 views
2

我有以下python structure directory structurePython的另一個腳本

login_logout_test.py我用下面的進口,當我運行此腳本一切工作正常調用腳本的時候輸入模塊(所有的模塊正常進口)

import sys, os 
parentPath = os.path.abspath("..") 
if parentPath not in sys.path: 
    sys.path.insert(0, parentPath) 
import common_test_functions as cts 
from functions import login_logout_functions as llf 

但是,當這個腳本(login_logout_test.py)由CommandRunner.py稱爲出現此錯誤:

No module named 'common_test_functions'

+0

當腳本由CommandRunner.py調用時,父目錄是相對於CommandRunner.py,不login_logout_test.py – EvanL00

+0

的父目錄我明白,但我想使腳本的輸入以這種方式,** login_logout_test.py **本身運行正常或由** CommandRunner.py ** –

+0

正確運行嘗試使用一個點而不是兩個 – EvanL00

回答

0

其實我已經做作解決我自己的問題:

import sys, os 
from selenium import webdriver 
# adding path to common_test_functions to the sys.path 
# so this module could be invoked 
parentPath = os.path.abspath("..\\..") 
if parentPath not in sys.path: 
     sys.path.append(parentPath) 
from functions import login_logout_functions as llf 
from tests import common_test_functions as cts 

也有一個文件,對於腳本參數擁有必要的。這裏是代碼在這兩種情況下這個文件的路徑(本身運行此腳本或其他腳本調用它):

parameters_directory_path = os.path.dirname(os.path.realpath(__file__)) 
parameters_file_name = "login_logout_test_parameters.tsv" 
parameters_file_path = os.path.join(parameters_file_path, parameters_file_name) 

如果有人有一個更好的,請張貼。

預先感謝您。

斯特凡

相關問題