0

I am in need to mock a glue job to check if it exists for a unit test case. The following code is used for it.

class GlueJob:
    """Function mocking glue job."""
    def custom_get_glue_job(self,glue_client):
        """Test Glue Job"""
        response = glue_client.get_job(JobName="abc")
        return response

import unittest
import sys
from unittest import mock
from mock import patch
class TestGlueJobs(unittest.TestCase):
    """Function mocking glue job"""
   
    @patch.object(GlueJob, 'custom_get_glue_job',return_value=True)
    def check_glue_job_exists(self, glue_job):
        """Function printing python version."""
        session = boto3.session.Session()
        glue_client = session.client('glue', region_name='us-west-1')
        GlueJob.custom_get_glue_job(glue_client)
        print("success")

glue_job = GlueJob
TestGlueJobs().check_glue_job_exists()

I am getting the following errors:

  1. No value for argument 'glue_client' in unbound method call
  2. No value for argument 'glue_job' in method call

I have passed on the values for both this argument. Not sure what I am missing here.

Thanks.

Bert Blommers
  • 1,788
  • 2
  • 13
  • 19
  • This question explains how to mock boto3-methods in a general way, and I think would solve your problem: https://stackoverflow.com/questions/37143597/mocking-boto3-s3-client-method-python/37143916#37143916 – Bert Blommers Nov 17 '22 at 20:45

0 Answers0