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:
parent
7f4f373e89
commit
0a612f24ac
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue