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\_pages.py:253: in register_page
    _validate.validate_use_pages(CONFIG)
D:\VENVS\8_dashboard_modbus_prediction_system-9lW2-ywX\lib\site-packages\dash\_validate.py:465: 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 page.py…

dash.register_page(name)

Complete error:

ERROR tests/test__decorator__protect_layout.py - 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…

try:
    dash.register_page(__name__)
except dash.exceptions.PageError:
    pass

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.

eg:
utils/functions.py

def my_func():

app.py

from utils.functions import my_func

pages/first_page.py

from utils.functions import my_func
1 Like