# When running pytest on a plugin: RuntimeError: Model class baserow.contrib.builder.pages.models.Page doesn't declare an explicit app\_label and isn't in an application in INSTALLED\_APPS

**URL:** <https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548>\
**Category:** Technical Help\
**Tags:** plugin\
**Created:** [April 4, 2023, 2:09pm UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548 "2023-04-04T14:09:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucw](https://community.baserow.io/user_avatar/community.baserow.io/lucw/32/609_2.png) [@lucw](https://community.baserow.io/u/lucw)\
**Post date:** [April 4, 2023, 2:09pm UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/1 "2023-04-04T14:09:24Z")

</div>

This used to work for me, so not sure whether this is a new issue after upgrading my plugin from 1.13.2 to 1.15.2.  
To run the tests, I get into the docker container and run pytest like this:

```auto
docker compose -f docker-compose.dev.yml exec baserow-vocabai-plugin /baserow.sh backend-cmd bash -c bash
cd /baserow/data/plugins/baserow_vocabai_plugin/backend/tests
pytest

```

a google search here suggests this is an import related issue, I plan on debugging this but wanted to post this in case anyone has faced the same problem.

```auto
        if getattr(meta, 'app_label', None) is None:
            if app_config is None:
                if not abstract:
> raise RuntimeError(
                        "Model class %s.%s doesn't declare an explicit "
                        "app_label and isn't in an application in "
                        "INSTALLED_APPS." % (module, name)
                    )
E RuntimeError: Model class baserow.contrib.builder.pages.models.Page doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

/baserow/venv/lib/python3.9/site-packages/django/db/models/base.py:113: RuntimeError

============================================================================================================= ERRORS ============================================================================================================== ________________________________________________________________________________ERROR at setup of test_can_query_starting_endpoint_as_authed_user________________________________________________________________________________

    @pytest.fixture
    def data_fixture():
> from .fixtures import Fixtures

/baserow/backend/src/baserow/test_utils/pytest_conftest.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _/baserow/backend/src/baserow/test_utils/fixtures/ __init__.py:4: in <module>
    from .application import ApplicationFixtures
/baserow/backend/src/baserow/test_utils/fixtures/application.py:1: in <module>
    from baserow.contrib.builder.models import Builder
/baserow/backend/src/baserow/contrib/builder/models.py:1: in <module>
    from baserow.contrib.builder.pages.models import Page
/baserow/backend/src/baserow/contrib/builder/pages/models.py:22: in <module>
    class Page(
/usr/lib/python3.9/abc.py:85: in __new__
    cls = super(). __new__ (mcls, name, bases, namespace, **kwargs)

```

---

<div class="post-metadata">

**Author:** ![lucw](https://community.baserow.io/user_avatar/community.baserow.io/lucw/32/609_2.png) [@lucw](https://community.baserow.io/u/lucw)\
**Post date:** [April 4, 2023, 2:30pm UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/2 "2023-04-04T14:30:26Z")

</div>

Looks like I can make the issue go away by adding this in `plugins/baserow_vocabai_plugin/backend/src/baserow_vocabai_plugin/config/settings/settings.py`:

```auto
settings.INSTALLED_APPS += ["baserow.contrib.builder"]

```

After that, my tests run. I have no idea what i’m doing though. Maybe I should stop resisting and just learn Django once and for all !

---

<div class="post-metadata">

**Author:** ![lucw](https://community.baserow.io/user_avatar/community.baserow.io/lucw/32/609_2.png) [@lucw](https://community.baserow.io/u/lucw)\
**Post date:** [April 5, 2023, 1:04am UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/3 "2023-04-05T01:04:11Z")

</div>

I ended up doing this in my plugin’s settings.py, seems like a safe thing to do:

```auto
import sys

def setup(settings):
    """
    This function is called after Baserow as setup its own Django settings file but
    before Django starts. Read and modify provided settings object as appropriate
    just like you would in a normal Django settings file. E.g.:

    settings.INSTALLED_APPS += ["some_custom_plugin_dep"]
    for db, value in settings.DATABASES:
        value['engine'] = 'some custom engine'
    """

    # see here: https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/2
    if "pytest" in sys.modules:
        settings.INSTALLED_APPS += ["baserow.contrib.builder"]

```

---

<div class="post-metadata">

**Author:** ![jrmi](https://community.baserow.io/user_avatar/community.baserow.io/jrmi/32/5042_2.png) [@jrmi](https://community.baserow.io/u/jrmi)\
**Post date:** [April 5, 2023, 7:41am UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/4 "2023-04-05T07:41:31Z")

</div>

Hey @lucw ,

Sorry about the issue you are facing. It’s related to a new unpublished WIP module we have added. I like the solution you’ve suggested and and I’ll try to fix the problem directly in the core to avoid impacting plugins writer. Thanks for reporting it. I’ll let you know when (if?) I have a better solution.

---

<div class="post-metadata">

**Author:** ![lucw](https://community.baserow.io/user_avatar/community.baserow.io/lucw/32/609_2.png) [@lucw](https://community.baserow.io/u/lucw)\
**Post date:** [April 6, 2023, 8:54am UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/5 "2023-04-06T08:54:48Z")

</div>

Great, thank you for your help !

---

<div class="post-metadata">

**Author:** ![jrmi](https://community.baserow.io/user_avatar/community.baserow.io/jrmi/32/5042_2.png) [@jrmi](https://community.baserow.io/u/jrmi)\
**Post date:** [April 19, 2023, 1:58pm UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/6 "2023-04-19T13:58:43Z")

</div>

For your information the patch has been merged but it hasn’t been released yet. See [Fix plugin tests (!1366) · Merge requests · Bram Wiepjes / baserow · GitLab](https://gitlab.com/bramw/baserow/-/merge_requests/1366) if you want to see the fix which is largely inspired by your solution 😉

---

<div class="post-metadata">

**Author:** ![lucw](https://community.baserow.io/user_avatar/community.baserow.io/lucw/32/609_2.png) [@lucw](https://community.baserow.io/u/lucw)\
**Post date:** [April 19, 2023, 11:28pm UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/7 "2023-04-19T23:28:27Z")

</div>

many thanks @jrmi, your work on this is appreciated !

---

<div class="post-metadata">

**Author:** ![lucw](https://community.baserow.io/user_avatar/community.baserow.io/lucw/32/609_2.png) [@lucw](https://community.baserow.io/u/lucw)\
**Post date:** [May 26, 2023, 9:38am UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/8 "2023-05-26T09:38:31Z")

</div>

@jrmi FYI looks like I had to undo the fix above in my plugin after upgrading my plugin to baserow 1.17.2.

---

<div class="post-metadata">

**Author:** ![jrmi](https://community.baserow.io/user_avatar/community.baserow.io/jrmi/32/5042_2.png) [@jrmi](https://community.baserow.io/u/jrmi)\
**Post date:** [May 26, 2023, 9:45am UTC](https://community.baserow.io/t/when-running-pytest-on-a-plugin-runtimeerror-model-class-baserow-contrib-builder-pages-models-page-doesnt-declare-an-explicit-app-label-and-isnt-in-an-application-in-installed-apps/2548/9 "2023-05-26T09:45:51Z")

</div>

Sorry about that, may be adding the same app twice is not a good idea 😃

However, i’m happy you don’t need your fix anymore.
