You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a Django project, I have a feature with three scenarios. These scenarios pass when run individually, two of them fail when running the whole feature and all fail when running all features in the project.
The failure happens in a step common to all three scenarios, in which a custom permission created in a database migration is attempted to be assigned to a user. The step looks something along the lines of
In the cases where this step fails, the error seems to be caused by not finding the permission in the database: django.contrib.auth.models.Permission.DoesNotExist: Permission matching query does not exist..
It seems as if the custom permissions added during the database migration are removed after each scenario runs, which explains the observations. I've looked into the code in the migration, but it doesn't look like anything fishy is happening there:
fromdjango.dbimportmigrationsdefforward_func(apps, schema_editor):
Permission=apps.get_model('auth', 'Permission')
ContentType=apps.get_model('contenttypes', 'ContentType')
content_type=ContentType.objects.get_for_model(apps.get_model('app_name', 'CustomUser'))
permission, _=Permission.objects.get_or_create(
codename='custom_permission',
defaults={
'name': 'custom permission',
'content_type': content_type
},
)
# backward_func defined hereclassMigration(migrations.Migration):
dependencies= [
# dependencies on the migrations of other apps
]
operations= [
migrations.RunPython(forward_func, backward_func),
]
When running Django tests I don't experience this issue, although these custom permissions are used in many test cases and there is a database cleanup happening per test case supposedly similar to the cleanup happening per feature scenario.
The text was updated successfully, but these errors were encountered:
In a Django project, I have a feature with three scenarios. These scenarios pass when run individually, two of them fail when running the whole feature and all fail when running all features in the project.
The failure happens in a step common to all three scenarios, in which a custom permission created in a database migration is attempted to be assigned to a user. The step looks something along the lines of
In the cases where this step fails, the error seems to be caused by not finding the permission in the database:
django.contrib.auth.models.Permission.DoesNotExist: Permission matching query does not exist.
.It seems as if the custom permissions added during the database migration are removed after each scenario runs, which explains the observations. I've looked into the code in the migration, but it doesn't look like anything fishy is happening there:
When running Django tests I don't experience this issue, although these custom permissions are used in many test cases and there is a database cleanup happening per test case supposedly similar to the cleanup happening per feature scenario.
The text was updated successfully, but these errors were encountered: