Issues with testing while using new pages feature

I want to do unit tests on the callbacks in my app. I’m using the new pages feature to create a multi-page app.

When I run pytest, I am seeing the following error:

D:\VENVS\8_dashboard_modbus_prediction_system-9lW2-ywX\lib\site-packages\dash\ in register_page
D:\VENVS\8_dashboard_modbus_prediction_system-9lW2-ywX\lib\site-packages\dash\ in validate_use_pages
    raise Exception("`dash.register_page()` must be called after app instantiation")
E   Exception: `dash.register_page()` must be called after app instantiation

It seems to be something others are experiencing and also discussed in the release post..

I just wanted to raise this issue here also to see if others have had any luck solving this problem. Given that these are two recent features, I understand that there may be issues getting them to work together.

I am facing same issue… Did you find solution?

This line is making troubles when I import function from…


Complete error:

ERROR tests/ - dash.exceptions.PageError: dash.register_page() must be called after app instantiation

I fixed this testing related issue… I would like to get opinion if this is the best way to approach it…

except dash.exceptions.PageError:

Typically it is better to import your functions from a utils file as far as I understand it. Something that is outside of the dash flow.


def my_func():

from utils.functions import my_func


from utils.functions import my_func
1 Like