これは私のフォルダ構造です
src/celery/初期化.py(空)
src/celery/utils.py
スクリプト/ __ init.py(空)
スクリプト/keep_alive.py
テスト/スクリプト/test_keep_alive.py
utils.pyコンテンツのコンテンツ
def get_auth_token():
print("getting auth token")
oauth_conf = get_oauth_config(celery_app_conf)
headers = {
'Content-Type': 'application/json'
}
payload = {
'grant_type': 'client_credentials',
'client_id': oauth_conf['client_id'],
'client_secret': oauth_conf['client_secret'],
'audience': oauth_conf['audience'],
}
response = requests.post(
oauth_conf['url'],
json=payload,
headers=headers
)
return response
def another_method():
return 1+2
test_keep_alive.pyの内容
class TestKeepAlive(TestBase, FixturesMixin):
@mock.patch('src.celery.utils.get_auth_token', return_value='')
def test_select_1_query(self, connection_mock):
KeepAlive().run()
#Do whatever after
keep_alive.pyの内容
class KeepAlive(Command):
def run(self):
auth_token = get_auth_token()
logging.info("KEEP ALIVE SUCCESS!
pytestを実行すると、
python -m pytest -v tests/scripts/test_keep_alive.py -s
まだ印刷中です「認証トークンの取得」私がそれをあざけった後でさえ。ここで明らかな何かが欠けていますか?
たくさんの助けをありがとう!
実際の関数ではなく、インポートをモックすることになっています。
適切なパスは
またはそれらの線に沿った何かが、あなたは少し実験する必要があります。