diff --git a/dash/dash.py b/dash/dash.py index bb8327e670..81033d9557 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -169,6 +169,18 @@ def _get_skip(text, divider=2): no_update = _callback.NoUpdate() # pylint: disable=protected-access +def init_dash_globals(): + """Ensure that all Dash global state is re-initialised.""" + _pages.PAGE_REGISTRY.clear() + + # this line of thinking could be extended to potentially clear the following: + # _pages.CONFIG + # _get_paths.CONFIG + # _callback.GLOBAL_CALLBACK_MAP + # _callback.GLOBAL_CALLBACK_LIST + # _callback.GLOBAL_INLINE_SCRIPTS + + # pylint: disable=too-many-instance-attributes # pylint: disable=too-many-arguments, too-many-locals class Dash: @@ -380,6 +392,8 @@ def __init__( # pylint: disable=too-many-statements url_base_pathname, routes_pathname_prefix, requests_pathname_prefix ) + init_dash_globals() + self.config = AttributeDict( name=name, assets_folder=os.path.join( @@ -2008,7 +2022,7 @@ def _import_layouts_from_pages(self): self.pages_folder.replace("\\", "/").lstrip("/").replace("/", ".") ) - module_name = ".".join([pages_folder, page_filename]) + module_name = ".".join([self.config.name, pages_folder, page_filename]) spec = importlib.util.spec_from_file_location( module_name, os.path.join(root, file) diff --git a/tests/integration/multi_page/test_pages_layout.py b/tests/integration/multi_page/test_pages_layout.py index d5abb51ff7..82ba0d6338 100644 --- a/tests/integration/multi_page/test_pages_layout.py +++ b/tests/integration/multi_page/test_pages_layout.py @@ -173,12 +173,11 @@ def test_pala003_meta_tags_custom(dash_duo): def test_pala004_no_layout_exception(): - error_msg = 'No layout found in module pages_error.no_layout_page\nA variable or a function named "layout" is required.' + error_msg = 'No layout found in module test_pages_layout.pages_error.no_layout_page\nA variable or a function named "layout" is required.' with pytest.raises(NoLayoutException) as err: Dash(__name__, use_pages=True, pages_folder="pages_error") - # clean up after this test, so the broken entry doesn't affect other pages tests - del dash.page_registry["pages_error.no_layout_page"] + del dash.page_registry["test_pages_layout.pages_error.no_layout_page"] assert error_msg in err.value.args[0] diff --git a/tests/integration/multi_page/test_pages_order.py b/tests/integration/multi_page/test_pages_order.py index 57d487f437..3f6715aea7 100644 --- a/tests/integration/multi_page/test_pages_order.py +++ b/tests/integration/multi_page/test_pages_order.py @@ -48,14 +48,14 @@ def test_paor001_order(dash_duo): "multi_layout3", "multi_layout2", "multi_layout1", - "pages.defaults", - "pages.metas", - "pages.not_found_404", - "pages.page1", - "pages.page2", - "pages.path_variables", - "pages.query_string", - "pages.redirect", + "test_pages_order.pages.defaults", + "test_pages_order.pages.metas", + "test_pages_order.pages.not_found_404", + "test_pages_order.pages.page1", + "test_pages_order.pages.page2", + "test_pages_order.pages.path_variables", + "test_pages_order.pages.query_string", + "test_pages_order.pages.redirect", ] dash_duo.start_server(app)