Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LookupError: No installed app with label 'tests' #192

Closed
Arussil opened this issue May 11, 2021 · 4 comments · Fixed by #201
Closed

LookupError: No installed app with label 'tests' #192

Arussil opened this issue May 11, 2021 · 4 comments · Fixed by #201
Labels
bug Something isn't working

Comments

@Arussil
Copy link

Arussil commented May 11, 2021

Short summary.

Expected behavior

I have a tests folder which contains baker_recipes, conftest, test files etc... #140 this worked:

from model_baker import baker

item = baker.make("tests.item_recipe")

Actual behavior

After installing latest model_bakery i get this error:

LookupError: No installed app with label 'tests'.

As "tests.item_recipe" is interpreted as a django app by _recipe:

def _recipe(name: str) -> Any:
    app_name, recipe_name = name.rsplit(".", 1)
    if "." in app_name:  # probably full path, not app name
        pkg = app_name
    else:
        pkg = apps.get_app_config(app_name).module.__package__
    return import_from_str(".".join((pkg, "baker_recipes", recipe_name)))

Possible solutions:

Moving baker_recipes.py in his own module inside tests does work, but something like:

def _recipe(name: str) -> Any:
    app_name, recipe_name = name.rsplit(".", 1)
    try:
        pkg = apps.get_app_config(app_name).module.__package__
    except LookupError:
        pkg = app_name
    return import_from_str(".".join((pkg, "baker_recipes", recipe_name)))

could probably work, haven't had the time to test it.

Versions

Python: 3.8.7
Django: 2.2.22
Model Bakery: 1.3.1

@berinhard
Copy link
Member

Hi @Arussil, is your app named "tests" tests? Because, from the project docs:

You don’t have to place necessarily your baker_recipes.py file inside your app’s root directory. If you have a tests directory within the app, for example, you can add your recipes inside it and still use make_recipe/prepare_recipe by adding the tests module to the string you’ve passed as an argument. For example: baker.make_recipe("shop.tests.customer_joe").

So, probably your call is missing the app name before the tests module in the import string.

@Arussil
Copy link
Author

Arussil commented May 12, 2021

Hello @berinhard , maybe i wasn't so clear on my example :D

This is the project folder:

- manage.py
- tests/
  - __init__.py
  - baker_recipes.py
  - conftest.py
  - unit/
  - integration/

"tests" it's not a django app and so it's not in INSTALLED_APPS: this setup worked with model_bakery 1.2.1, before the change to _recipe.

@berinhard berinhard added the bug Something isn't working label May 14, 2021
@berinhard
Copy link
Member

Ow, I see! Thanks the explanation @Arussil! So, this is definitely a bug introduced by 1.2.1.

@timjklein36
Copy link
Collaborator

@Arussil In your example, you call baker.make. Did you mean baker.make_recipe? I don't think the code path executed by baker.make has logic for retrieving recipes and does not call _recipe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants