Provides a hook for outputting type-specific assertion messages Expected to return a list or strings, where each string will be printed as a new line in the result output report on assertion failure.
(op, left, right)
| 204 | |
| 205 | |
| 206 | def pytest_assertrepr_compare(op, left, right): |
| 207 | """ |
| 208 | Provides a hook for outputting type-specific assertion messages |
| 209 | |
| 210 | Expected to return a list or strings, where each string will be printed as a new line |
| 211 | in the result output report on assertion failure. |
| 212 | """ |
| 213 | if isinstance(left, QueryTestResult) and isinstance(right, QueryTestResult) and \ |
| 214 | op == "==": |
| 215 | result = ['Comparing QueryTestResults (expected vs actual):'] |
| 216 | for l, r in zip(left.rows, right.rows): |
| 217 | result.append("%s == %s" % (l, r) if l == r else "%s != %s" % (l, r)) |
| 218 | if len(left.rows) != len(right.rows): |
| 219 | result.append('Number of rows returned (expected vs actual): ' |
| 220 | '%d != %d' % (len(left.rows), len(right.rows))) |
| 221 | |
| 222 | # pytest has a bug/limitation where it will truncate long custom assertion messages |
| 223 | # (it has a hardcoded string length limit of 80*8 characters). To ensure this info |
| 224 | # isn't lost, always log the assertion message. |
| 225 | LOG.error('\n'.join(result)) |
| 226 | return result |
| 227 | |
| 228 | # pytest supports printing the diff for a set equality check, but does not do |
| 229 | # so well when we're doing a subset check. This handles that situation. |
| 230 | if isinstance(left, set) and isinstance(right, set) and op == '<=': |
| 231 | # If expected is not a subset of actual, print out the set difference. |
| 232 | result = ['Items in expected results not found in actual results:'] |
| 233 | result.extend(list(left - right)) |
| 234 | result.append('Items in actual results:') |
| 235 | result.extend(list(right)) |
| 236 | LOG.error('\n'.join(result)) |
| 237 | return result |
| 238 | |
| 239 | |
| 240 | def pytest_xdist_setupnodes(config, specs): |