I am trying to write a testcase for a Dash callback function in a page which store selected rows of 2 datatables into dash_core_components.Store
, and determine the state by dash.callback_context
Sample callback function in index.py
@app.callback(
Output('rows-store', 'data'),
Input('datatable1', 'selected_rows'),
Input('datatable2', 'selected_rows'),
)
def store_row_selection(row1: list, row2: list) -> dict:
ctx = dash.callback_context
if not ctx.triggered:
return {'row-index-v1': [0], 'row-index-v2': [0]}
else:
return {'row-index-v1': row1, 'row-index-v2': row2}
Sample testcase in test.py
def test_store_row_selection_1(app_datatable):
r1 = [0]
r2 = [1]
result = store_row_selection(r1, r2)
assert type(result) is dict
However, Pytest throws an exception when running, what is the proper way to test a callback function and how can I get this to work?
@wraps(func)
def add_context(*args, **kwargs):
> output_spec = kwargs.pop("outputs_list")
E KeyError: 'outputs_list'