2017-02-27 135 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) 

如果有人有一个更好的,请张贴。

预先感谢您。

斯特凡

相关问题