# Issues with testing while using new pages feature

**URL:** <https://community.plotly.com/t/issues-with-testing-while-using-new-pages-feature/67690>\
**Category:** Dash Python\
**Created:** [September 6, 2022, 1:30am UTC](https://community.plotly.com/t/issues-with-testing-while-using-new-pages-feature/67690 "2022-09-06T01:30:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harmanato](https://avatars.discourse-cdn.com/v4/letter/h/ce7236/32.png) [@harmanato](https://community.plotly.com/u/harmanato)\
**Post date:** [September 6, 2022, 1:30am UTC](https://community.plotly.com/t/issues-with-testing-while-using-new-pages-feature/67690/1 "2022-09-06T01:30:32Z")

</div>

I want to do [unit tests](https://dash.plotly.com/testing) on the callbacks in my app. I’m using the new [`pages` feature](https://dash.plotly.com/urls) to create a multi-page app.

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

```nohighlight
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](https://github.com/plotly/dash/issues/2193) and also discussed in the [release post.](https://community.plotly.com/t/dash-2-6-released-background-callbacks-unit-testing-persistent-selections-dropdown-features/66322/3).

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.

---

<div class="post-metadata">

**Author:** ![Milan](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/milan/32/18754_2.png) [@Milan](https://community.plotly.com/u/Milan)\
**Post date:** [December 28, 2023, 12:00am UTC](https://community.plotly.com/t/issues-with-testing-while-using-new-pages-feature/67690/2 "2023-12-28T00:00:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Milan](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/milan/32/18754_2.png) [@Milan](https://community.plotly.com/u/Milan)\
**Post date:** [December 28, 2023, 12:13am UTC](https://community.plotly.com/t/issues-with-testing-while-using-new-pages-feature/67690/3 "2023-12-28T00:13:34Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [December 28, 2023, 1:43am UTC](https://community.plotly.com/t/issues-with-testing-while-using-new-pages-feature/67690/4 "2023-12-28T01:43:01Z")

</div>

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

```auto
def my_func():

```

app.py

```auto
from utils.functions import my_func

```

pages/first\_page.py

```auto
from utils.functions import my_func

```
