I am writing tests in my app that will test whether a method was called. This is running in Python 3.4.3 and pytest-2.9.2. I am new to PyTest but very familiar with RSpec and Jasmine. I'm not sure how to setup the test so that it will test that imaplib.IMAP4_SSL is called.
My app structure:
/myApp
__init__.py
/shared
__init__.py
email_handler.py
/tests
__init__.py
test_email_handler.py
email_handler.py
import imaplib
def email_conn(host):
mail = imaplib.IMAP4_SSL(host)
return mail;
What I have so far for my test: test_email_handler.py
import sys
sys.path.append('.')
from shared import email_handler
def test_email_handler():
email_handler.email_conn.imaplib.IMAP4_SSL.assert_called_once
This obviously fails. How can I setup this test so that it tests if imaplib.IMAP4_SSL is called? Or is there a better way to setup the test suite in my app so this will support testing more effectively?