From 1e4285d3772454b0beb693c8c4bede88499b736d Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Thu, 29 Jul 2021 11:06:02 +0200 Subject: [PATCH] GREG-5: Moving test database setup --- greg/tests/api/test_person.py | 12 ------------ greg/tests/conftest.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/greg/tests/api/test_person.py b/greg/tests/api/test_person.py index a2ee1249..0da8f3d2 100644 --- a/greg/tests/api/test_person.py +++ b/greg/tests/api/test_person.py @@ -7,7 +7,6 @@ from rest_framework.status import HTTP_200_OK from rest_framework.test import APIClient from greg.models import Person -from greg.tests.populate_database import DatabasePopulation @pytest.fixture @@ -41,17 +40,6 @@ def person_bar() -> Person: ) -# The database is populated once when scope is session. -# If the scope is changed to function some additional -# logic is needed to make sure the old data is cleaned -# before the seeding is run again -@pytest.fixture(scope="session") -def setup_db_test_data(django_db_setup, django_db_blocker): - with django_db_blocker.unblock(): - database_seeder = DatabasePopulation() - database_seeder.populate_database() - - @pytest.mark.django_db def test_get_person(client, person_foo): resp = client.get(reverse("person-detail", kwargs={"id": person_foo.id})) diff --git a/greg/tests/conftest.py b/greg/tests/conftest.py index 9817637e..290c0a14 100644 --- a/greg/tests/conftest.py +++ b/greg/tests/conftest.py @@ -3,4 +3,19 @@ import logging # faker spams the logs with localisation warnings # see https://github.com/joke2k/faker/issues/753 +import pytest + +from greg.tests.populate_database import DatabasePopulation + logging.getLogger("faker").setLevel(logging.ERROR) + + +# The database is populated once when scope is session. +# If the scope is changed to function some additional +# logic is needed to make sure the old data is cleaned +# before the seeding is run again +@pytest.fixture(scope="session") +def setup_db_test_data(django_db_setup, django_db_blocker): + with django_db_blocker.unblock(): + database_seeder = DatabasePopulation() + database_seeder.populate_database() -- GitLab