Search code examples
pythonunit-testingpytestpython-unittestpython-mock

How to write a pytest or unittest on my code?


I am new to unit testing. I am trying to test if function is called and if the schedule time is correct on the below.

The python filename is #schedule.py

def screenshot():
   ob=Screenshot_Clipping.Screenshot()
   driver.get(url)
   img_url=ob.full_Screenshot(driver, save_path = path)
   email_it(path)
   driver.close()
screenshot()

Solution

  • Try this,

    def test_screenshot(mocker):
        url = 'url'
        path = /your/path/
    
        mocker.patch('screenshot.env', return_value = (url, path))
        
        mocker.patch('screenshot.email_it', return_value = (path))
    
        screenshot()