tests: use tabulate to compare tables (#38067)

Comparing strings with assert gives better diffs thant comparing list of
lists when using the pytest's `-vv` option.
This commit is contained in:
Benjamin Dauvergne 2019-11-30 03:52:14 +01:00
parent 7f4f373e89
commit 0a612f24ac
2 changed files with 15 additions and 1 deletions

View File

@ -1,7 +1,9 @@
import json
import os
import re
import pytest
from tabulate import tabulate
from utils import login, get_table
@ -20,6 +22,14 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize(['visualization'], [[x] for x in tables])
def assert_equal_tables(table1, table2):
t1 = tabulate(table1)
t2 = tabulate(table2)
t1 = re.sub(' +', ' ', t1)
t2 = re.sub(' +', ' ', t2)
assert t1 == t2
@pytest.fixture(autouse=True)
def freezetime(freezer):
freezer.move_to('2018-12-07 16:53:00')
@ -31,4 +41,7 @@ def test_simple(schema2, app, admin, visualization):
visualization_page = response.click(lambda x: x == visualization)
assert 'big-msg-info' not in visualization_page
assert schema2['tables'][visualization] == get_table(visualization_page)
table = get_table(visualization_page)
assert_equal_tables(
schema2['tables'][visualization],
table)

View File

@ -24,6 +24,7 @@ deps =
WebTest
django-webtest<1.9.3
pyquery
tabulate
commands =
dj111: py.test {posargs: --junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=bijoe tests/}
[pytest]