Ошибка Pytest во время сбора: как смоделировать переменные env в моем коде разработки? - PullRequest
0 голосов
/ 24 апреля 2020

Pytest выдает ошибку, необходимую для заполнения переменных env в моем исходном файле dev. Могу ли я добавить где-нибудь фиктивное значение, чтобы оно могло продолжаться? Кажется, чтобы импортировать execute.download, pytest должен запустить код строки подключения?

Я использую pytest, как показано ниже:

    #### In execute.py  ####
    import sys, os, uuid,
    from azure.kusto.data.request import KustoClient, KustoConnectionStringBuilder, ClientRequestProperties


    ##Auth for connecting to DB

    cluster = os.environ.get("CLUSTER_QUERY_URL")
    client_id = os.environ.get("CLIENT_ID")
    client_secret = os.environ.get("CLIENT_SECRET")
    tenant_id = os.environ.get("TENANT_ID")

    kcsb = KustoConnectionStringBuilder.with_aad_application_key_authentication(
        cluster, client_id, client_secret, tenant_id)

    kusto_client = KustoClient(kcsb)


    ##After Auth, I started other functions

    def download(name):
        with open(name, 'wb') as file:
        data = '42'
        file.write('42')



    ##### In test_execute.py ####
    import pytest
    from uuid import uuid4
    from execute import download  #this should be where it has error because i didn't specify variables.

       def test_download():
           x = download()
           assert x == '42'

У меня есть ошибка: Кажется, мне нужно передать значение with_aad_application_key_authentication().

===================================================================================== ERRORS ======================================================================================
_____________________________________________________________________ ERROR collecting test_execute_query.py ______________________________________________________________________
test_execute_query.py:4: in <module>
    from execute_query import download_query
../execute_query.py:16: in <module>
    cluster, client_id, client_secret, tenant_id)
../../../../.pyenv/versions/3.7.3/lib/python3.7/site-packages/azure/kusto/data/request.py:202: in with_aad_application_key_authentication
    _assert_value_is_valid(aad_app_id)
../../../../.pyenv/versions/3.7.3/lib/python3.7/site-packages/azure/kusto/data/request.py:431: in _assert_value_is_valid
    raise ValueError("Should not be empty")
E   ValueError: Should not be empty
============================================================================= short test summary info =============================================================================
ERROR test_execute_query.py - ValueError: Should not be empty
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================================ 1 error in 1.17s =================================================================================
...