I've got this very simple class to connect to a MSSQL-server:
sql.py
import pymssql
class SQL:
def __init__(self, config_file, mode):
# I'm actually loading this from a file but have shortened it here
self.config = '{"dev": {"host": "host.com"}}'
db = pymssql.connect(**self.config)
self.cursor = db.cursor(as_dict=True)
def query(self, query):
self.cursor.execute(query)
return self.cursor.fetchall()
def rows(self):
return self.cursor.rowcount
I would like to add some unittests of said code and started out as so:
sql_test.py
import unittest
from unittest.mock import patch
class Test(unittest.TestCase):
"""Test the SQL component."""
@patch('module.sql.SQL')
def test_initialization(self, sql):
self.config = '{"dev": {"host": "host.com"}}'
self.cursor = {}
Running tox, however, returns:
E ImportError: No module named 'pymssql'
Any thoughts on what could be improved in the code to solve the situation?
Edit: I have installed pymssql in my venv: Requirement already satisfied: pymssql in /home/patrik/PycharmProjects/fin-data/venv/lib/python3.5/site-packages. It's more likely related to my inability to use Mock than module not being available in my venv.
Thanks, Patrik