|
36 | 36 | from warnings import warn
|
37 | 37 | from testutils import *
|
38 | 38 |
|
| 39 | +# Some tests have fallback code for known driver issues. |
| 40 | +# Change this value to False to bypass the fallback code, e.g., to see |
| 41 | +# if a newer version of the driver has fixed the underlying issue. |
| 42 | +# |
| 43 | +handle_known_issues = True |
| 44 | + |
39 | 45 | _TESTSTR = '0123456789-abcdefghijklmnopqrstuvwxyz-'
|
40 | 46 |
|
41 | 47 | def _generate_test_string(length):
|
@@ -87,6 +93,54 @@ def driver_type_is(self, type_name):
|
87 | 93 | elif type_name == 'freetds':
|
88 | 94 | return ('tdsodbc' in driver_name)
|
89 | 95 |
|
| 96 | + def handle_known_issues_for(self, type_name, print_reminder=False): |
| 97 | + """ |
| 98 | + Checks driver `type_name` and "killswitch" variable `handle_known_issues` to see if |
| 99 | + known issue handling should be bypassed. Optionally prints a reminder message to |
| 100 | + help identify tests that previously had issues but may have been fixed by a newer |
| 101 | + version of the driver. |
| 102 | +
|
| 103 | + Usage examples: |
| 104 | +
|
| 105 | + # 1. print reminder at beginning of test (before any errors can occur) |
| 106 | + # |
| 107 | + def test_some_feature(self): |
| 108 | + self.handle_known_issues_for('freetds', print_reminder=True) |
| 109 | + # (continue with test code) |
| 110 | +
|
| 111 | + # 2. conditional execution of fallback code |
| 112 | + # |
| 113 | + try: |
| 114 | + # (some test code) |
| 115 | + except pyodbc.DataError: |
| 116 | + if self.handle_known_issues_for('freetds'): |
| 117 | + # FREETDS_KNOWN_ISSUE |
| 118 | + # |
| 119 | + # (fallback code to work around exception) |
| 120 | + else: |
| 121 | + raise |
| 122 | + """ |
| 123 | + if self.driver_type_is(type_name): |
| 124 | + if handle_known_issues: |
| 125 | + return True |
| 126 | + else: |
| 127 | + if print_reminder: |
| 128 | + print("Known issue handling is disabled. Does this test still fail?") |
| 129 | + return False |
| 130 | + |
| 131 | + def driver_type_is(self, type_name): |
| 132 | + recognized_types = { |
| 133 | + 'msodbcsql': '(Microsoft) ODBC Driver xx for SQL Server', |
| 134 | + 'freetds': 'FreeTDS ODBC', |
| 135 | + } |
| 136 | + if not type_name in recognized_types.keys(): |
| 137 | + raise KeyError('"{0}" is not a recognized driver type: {1}'.format(type_name, list(recognized_types.keys()))) |
| 138 | + driver_name = self.cnxn.getinfo(pyodbc.SQL_DRIVER_NAME).lower() |
| 139 | + if type_name == 'msodbcsql': |
| 140 | + return ('msodbcsql' in driver_name) or ('sqlncli' in driver_name) or ('sqlsrv32.dll' == driver_name) |
| 141 | + elif type_name == 'freetds': |
| 142 | + return ('tdsodbc' in driver_name) |
| 143 | + |
90 | 144 | def get_sqlserver_version(self):
|
91 | 145 | """
|
92 | 146 | Returns the major version: 8-->2000, 9-->2005, 10-->2008
|
@@ -1651,6 +1705,10 @@ def test_tvp(self):
|
1651 | 1705 | # pyodbc supports queries with table valued parameters in sql server
|
1652 | 1706 | #
|
1653 | 1707 |
|
| 1708 | + if self.handle_known_issues_for('freetds', print_reminder=True): |
| 1709 | + warn('FREETDS_KNOWN_ISSUE - test_tvp: test cancelled.') |
| 1710 | + return |
| 1711 | + |
1654 | 1712 | # (Don't use "if exists" since older SQL Servers don't support it.)
|
1655 | 1713 | try:
|
1656 | 1714 | self.cursor.execute("drop procedure SelectTVP")
|
|
0 commit comments