1

我在 Mac 上收到以下导入错误:

ImportError: No module named Conf_Reader

以下是我的 Python 代码的几行初始代码:

import dotenv
import os
import testrail
import Conf_Reader

#setup the testrail client and connect to the testrail instance
def get_testrail_client():
    testrail_file = os.path.join(os.path.dirname(__file__),'testrail.env')
    testrail_url = Conf_Reader.get_value(testrail_file,'TESTRAIL_URL')
    client = testrail.APIClient(testrail_url)
..
..
..

到目前为止,尝试使用 pip 并找不到任何安装资源。

4

2 回答 2

3

我在 Mac 上遇到了同样的问题。为避免使用其他独立性,您可以跳过使用 env。但作为变量传递:

# create a credential.py
TESTRAIL_URL='https://testrail.com/testrail'
TESTRAIL_USER='xxxxx'
TESTRAIL_PASSWORD = 'xxxxx'
# on your update_testrail.py
from credential import TESTRAIL_URL, 
TESTRAIL_USER, 
TESTRAIL_PASSWORD

testrail_url = TESTRAIL_URL
client = testrail.APIClient(testrail_url)
# Get and set the TestRail User and Password
client.user = TESTRAIL_USER
client.password = TESTRAIL_PASSWORD
于 2018-03-21T20:23:41.703 回答
0

他们应该链接到https://bangladroid.wordpress.com/2016/08/20/create-separate-credential-files-for-selenium-python/

它解释您制作自己的“Conf_Reader.py”文件的地方如下:

"""
A simple conf reader.
For now, we just use dotenv and return a key.
"""

import dotenv,os

def get_value(conf,key):
    # type: (object, object) -> object
    "Return the value in conf for a given key"
    value = None
    try:
        dotenv.load_dotenv(conf)
        value = os.environ[key]
    except Exception,e:
        print 'Exception in get_value'
        print 'file: ',conf
        print 'key: ',key

    return value
于 2019-04-05T21:16:20.650 回答