Skip to content

Commit

Permalink
update sqlservertests.py for FreeTDS known issue with test_tvp
Browse files Browse the repository at this point in the history
  • Loading branch information
gordthompson authored and mkleehammer committed Feb 23, 2019
1 parent 84e9d5d commit 2da735e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests2/sqlservertests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
from warnings import warn
from testutils import *

# Some tests have fallback code for known driver issues.
# Change this value to False to bypass the fallback code, e.g., to see
# if a newer version of the driver has fixed the underlying issue.
#
handle_known_issues = True

_TESTSTR = '0123456789-abcdefghijklmnopqrstuvwxyz-'

def _generate_test_string(length):
Expand Down Expand Up @@ -87,6 +93,54 @@ def driver_type_is(self, type_name):
elif type_name == 'freetds':
return ('tdsodbc' in driver_name)

def handle_known_issues_for(self, type_name, print_reminder=False):
"""
Checks driver `type_name` and "killswitch" variable `handle_known_issues` to see if
known issue handling should be bypassed. Optionally prints a reminder message to
help identify tests that previously had issues but may have been fixed by a newer
version of the driver.
Usage examples:
# 1. print reminder at beginning of test (before any errors can occur)
#
def test_some_feature(self):
self.handle_known_issues_for('freetds', print_reminder=True)
# (continue with test code)
# 2. conditional execution of fallback code
#
try:
# (some test code)
except pyodbc.DataError:
if self.handle_known_issues_for('freetds'):
# FREETDS_KNOWN_ISSUE
#
# (fallback code to work around exception)
else:
raise
"""
if self.driver_type_is(type_name):
if handle_known_issues:
return True
else:
if print_reminder:
print("Known issue handling is disabled. Does this test still fail?")
return False

def driver_type_is(self, type_name):
recognized_types = {
'msodbcsql': '(Microsoft) ODBC Driver xx for SQL Server',
'freetds': 'FreeTDS ODBC',
}
if not type_name in recognized_types.keys():
raise KeyError('"{0}" is not a recognized driver type: {1}'.format(type_name, list(recognized_types.keys())))
driver_name = self.cnxn.getinfo(pyodbc.SQL_DRIVER_NAME).lower()
if type_name == 'msodbcsql':
return ('msodbcsql' in driver_name) or ('sqlncli' in driver_name) or ('sqlsrv32.dll' == driver_name)
elif type_name == 'freetds':
return ('tdsodbc' in driver_name)

def get_sqlserver_version(self):
"""
Returns the major version: 8-->2000, 9-->2005, 10-->2008
Expand Down Expand Up @@ -1651,6 +1705,10 @@ def test_tvp(self):
# pyodbc supports queries with table valued parameters in sql server
#

if self.handle_known_issues_for('freetds', print_reminder=True):
warn('FREETDS_KNOWN_ISSUE - test_tvp: test cancelled.')
return

# (Don't use "if exists" since older SQL Servers don't support it.)
try:
self.cursor.execute("drop procedure SelectTVP")
Expand Down
4 changes: 4 additions & 0 deletions tests3/sqlservertests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,10 @@ def test_tvp(self):
# pyodbc supports queries with table valued parameters in sql server
#

if self.handle_known_issues_for('freetds', print_reminder=True):
warn('FREETDS_KNOWN_ISSUE - test_tvp: test cancelled.')
return

# (Don't use "if exists" since older SQL Servers don't support it.)
try:
self.cursor.execute("drop procedure SelectTVP")
Expand Down

0 comments on commit 2da735e

Please sign in to comment.