Question

Is it possible to use Pytest with Django without using django-pytest 3rd party app?

I had tried to set this up, but kept running into random errors, like pytest couldn't find the DJANGO_SETTINGS_MODULE. Then I fixed the path, but the normal python manage.py runserver then couldn't find the DJANGO_SETTINGS_MODULE. I'm running:

Pytest 2.5.4
Python 3.4.0
Django 1.6.2 

If it is possible, would you be able to provide a setup example of where to put the tests/ directory, etc... within the project so Pytest works?

Thanks

Was it helpful?

Solution

Hmm, py.test 2.5.4 does not exist afaik.

Anyway, assuming you mean to ask whether it is possible to avoid the pytest-django plugin to test Django using py.test: the short answer is no.

The long answer is yes, but it is extremely difficult to get it all to work and you will basically write at least a minimal version of pytest-django in the conftest.py file. The pytest-django plugin was created specifically to work around all the weirdness which Django does with much global state and other hidden magic.

OTOH looking at the pytest-django source would probably help you kickstart such an effort. However you may consider thinking about what it is of pytest-django you do not like and maybe file an enhancement request to improve it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top