HypothesisWorks / hypothesis

Hypothesis is a powerful, flexible, and easy to use library for property-based testing.
https://hypothesis.works
Other
7.57k stars 587 forks source link

hypothesis.extra.django.TestCase vs. Django INSTALLED_APPS #3716

Open erikrw opened 1 year ago

erikrw commented 1 year ago

Hello, I'm trying out Hypothesis 6.82.2 on my Django 4.2 project.

Importing hypothesis.extra.django.TestCase fails with "RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS."

The error is triggered by hypothesis/extra/django/_fields.py doing from django.contrib.auth.forms import UsernameField

It can be fixed by adding 'django.contrib.contenttypes' to the INSTALLED_APPS setting.

However, I would like to use Hypothesis without modifying my INSTALLED_APPS setting.

Ideally, Hypothesis should use UsernameField when it is available, and not register strategies for it when it is not available. UsernameField is available when 'django.contrib.contenttypes' and 'django.contrib.auth' are in INSTALLED_APPS, as far as I can tell.

Would you be open to such a change?

Zac-HD commented 3 months ago

@jams2 this might be relevant to your interests?

jams2 commented 3 months ago

@Zac-HD certainly. I'm afk for 2 weeks, but can take a look if this is still open when I'm back.