python - Pytest and Django settings runtime changes - Stack ...
stackoverflow.com › questions › 40496051Nov 09, 2016 · import uuid import pytest import tempfile from django.conf import settings from django.contrib.auth.models import User @pytest.fixture (scope='session', autouse=True) def set_media_temp_folder (): with tempfile.TemporaryDirectory () as temp_dir: settings.MEDIA_ROOT = temp_dir yield None def create_normal_user () -> User: username = str (uuid.uuid4 ()) [:30] user = User.objects.create (username=username) user.set_password ('12345') user.save () return user @pytest.fixture def ...
Testing Your Django App With Pytest
https://djangostars.com/blog/django-pytest-testing10.09.2021 · Point your Django settings to pytest You need to tell pytest which Django settings should be used for test runs. The easiest way to achieve this is to create a pytest configuration file with this information. Create a file called pytest.ini in your project root directory that contains: [pytest] DJANGO_SETTINGS_MODULE = yourproject.settings