-1

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()
  • change the file name as test_schedule.py , pytest will scan files with test_* and you need to add assert statements for marking test cases as pass or failed – Sandeep Lade Apr 09 '21 at 02:07
  • 1
    Few issues I see here. I suggest reading the [documentation](https://docs.python.org/3/library/unittest.mock.html). The initial guide should give you a good introduction. To point out a couple of issues in your code to help: In your `test_capture`, you are trying to call `assert_called_once`. However, you are never "mocking" anything within `schedule.function1.capture`. So, trying to access the `mock` method `assert_called_once` from your *real* code will not work. – idjaw Apr 09 '21 at 02:31
  • Also, `assert_called_once` is a method, so when you get things working, make sure you call it: `assert_called_once()`. Another item to point out in your second test file `test_schedule2.py`. Your `assert` is not using the *equality* properly. You want to use `==` and not `=`. The single `=` is meant for assignment, double `==` is for equality. – idjaw Apr 09 '21 at 02:33
  • @idjaw Can you help me with an example of how i could use mock with my code? – Aishwarya Prabhu Apr 09 '21 at 04:42

1 Answers1

1

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()
Amogh Katwe
  • 196
  • 11