0

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

Patrik
  • 1
  • 1
  • 3
  • Possible duplicate of [Trouble running python unit tests with tox - ImportError for module that is already installed](https://stackoverflow.com/questions/46854650/trouble-running-python-unit-tests-with-tox-importerror-for-module-that-is-alre) – Uyghur Lives Matter Feb 04 '18 at 19:52
  • @cpburnz I'm not sure that's the case here. 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. – Patrik Feb 04 '18 at 20:01
  • Did you instruct Tox that *pymssql* is a dependency? Tox uses its own virtual environment to my understanding. I don't think installing *pymssql* in your virtual env. is enough. – Uyghur Lives Matter Feb 04 '18 at 20:43
  • Yes, pymssql is in my requirements.txt which is a parts of deps in tox.ini. – Patrik Feb 04 '18 at 21:11

0 Answers0