# Python : Testing : pytest : django ## pyproject.toml ```toml [ tool.pytest.ini_options ] DJANGO_SETTINGS_MODULE = "test.settings" # or use env var ``` ## Misc #### Startup pytest-django calls `django.setup()` automatically. If you want to do anything before this, you have to create a pytest plugin. #### Disabling Migrations Using `--no-migrations` will disable Django migrations and create the database by inspecting all models. It may be faster when there are several migrations to run in the database setup. #### Overriding Settings with Fixtures ```python @pytest.fixture( autouse=True ) def override_foo_setting( settings ): settings.FOO = 42 ``` #### Using the Database Options: - use `django.test.TestCase` - module-level: `pytestmark = [ pytest.mark.django_db, ...other-marks... ]` - per-class or method: `@pytest.mark.django_db`