behave / behave-django

Behave BDD integration for Django
https://behave-django.readthedocs.io/
MIT License
205 stars 46 forks source link

Tests using the Django test project do not work with newer versions of Django #94

Closed pydolan closed 5 years ago

pydolan commented 5 years ago

When setting up my test environment to run tests, pip installed Django 2.2 (since the requirements are for Django >= 1.11). When running the tests, Django errors about several settings being defined incorrectly.

ERRORS:
?: (admin.E404) 'django.contrib.messages.context_processors.messages' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin application.
?: (admin.E408) 'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE in order to use the admin application.
?: (admin.E409) 'django.contrib.messages.middleware.MessageMiddleware' must be in MIDDLEWARE in order to use the admin application.

I'll push up a PR shortly

bittner commented 5 years ago

Add a line for Django 2.2 in tox.ini and go from there (see my explanations in #93). That should work.

The Django version specified in requirements.txt, which is used by setup.py is really just for saying, "Hey, use an older version of behave-django for older Djangos" (for people reading source code). We should probably remove it or make it a soft-dependency with setuptools. -- This is the usual, and actually relevant, debate about including dependencies in Python packages.

Thanks for reporting that this is actually an issue!

bittner commented 5 years ago

This should work now when you run behave-django off the master branch.

Adarshptl123 commented 4 years ago

Can you explain this

bittner commented 4 years ago

There was a release on April 16, 2019 (v1.3.0), which includes the fix to the test project that was added on April 04, 2019 (see link above).

adnanrizwee commented 4 years ago

1) Go to settings.py of your project

2) Cut these three lines from MIDDLEWARE_CLASSES :

'django.contrib.sessions.middleware.SessionMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware',

3) Now paste the code given below right after MIDDLEWARE_CLASSES :

MIDDLEWARE = [ 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ]

bittner commented 4 years ago

@adnanrizwee I'm not sure I understand: You're using both the MIDDLEWARE_CLASSES and the MIDDLEWARE in your Django settings together? Do you have a specific reason for that? And which Django version do you run?