ValueError:请设置您的 RAVE_SECRET_KEY 环境变量。否则,将 publicKey 和 SecretKey 作为参数传递并设置 usingEnv

问题描述 投票:0回答:1

我正在尝试使用 pytest 工具为我的 Flask 应用程序编写单元和功能测试。我有这个装置:

@pytest.fixture
def app():
    os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/home/xxxxxxxx/Documents/dudu-docs/dudu-api/xxxxxxxxxxxxxxxxxxxxxxxxxxxx.json'
    os.environ['CONFIG_TYPE'] = 'config.TestingConfig'
    os.environ['RAVE_SECRET_KEY'] = 'FLWSECK_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    os.environ['RAVE_PUBLIC_KEY'] = 'FLWPUBK_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    flask_app = create_app()
    flask_app.config['TESTING'] = True
    flask_app.config['GOOGLE_APPLICATION_CREDENTIALS'] = os.getenv('GOOGLE_APPLICATION_CREDENTIALS')

    # Create a test client using the Flask application configured for testing
    with flask_app.test_client() as testing_client:
        # Establish an application context
        with flask_app.app_context():
            yield testing_client  # this is where the testing happens!

这是实际测试:

def test_is_valid_data_username_success(app):
    data = 'john_doe'
    mtype = 'username'
    result = is_valid_data(data=data, mtype=mtype)
    assert result == True

我正在使用 flutterwave api 并通过代码中的环境变量添加所需的键,但出现此错误:

raise ValueError(
E   ValueError: Please set your RAVE_SECRET_KEY environment variable. Otherwise, pass publicKey and secretKey as arguments and set usingEnv to false
collected 0 items / 1 error

我当前的IDE是pycharm,但是使用终端命令

pytest ...
仍然出现上述错误。我需要帮助来确定为什么我的 RAVE 变量没有被选取。

python-3.x pytest flask-restful
1个回答
0
投票

错误显示

Please set your RAVE_SECRET_KEY environment variable
,看起来设置环境时
RAVE_SECRET_KEY
拼写错误。

os.environ['RAVE_SECRETE_KEY'] = 'FLWSECK_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

应该是

os.environ['RAVE_SECRET_KEY'] = 'FLWSECK_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
© www.soinside.com 2019 - 2024. All rights reserved.