I am writing tests in my application that will check if a method has been called. This is done 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 set up the test so that it tests the imaplib.IMAP4_SSL call.
My application 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 before 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 to configure this test to check if imaplib.IMAP4_SSL is called? Or is there a better way to set up a test suite in my application so that it supports testing more effectively?
source
share