Skip to content

Commit

Permalink
change to cleanup instead of transaction as a check
Browse files Browse the repository at this point in the history
  • Loading branch information
collerek committed Jun 9, 2024
1 parent 39f6eeb commit 1871aca
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/test_hashes/test_many_to_many.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ormar
import pymysql
import pytest
import pytest_asyncio

from tests.lifespan import init_tests
from tests.settings import create_config
Expand Down Expand Up @@ -52,10 +53,25 @@ class AuthorXPosts(ormar.Model):
create_test_database = init_tests(base_ormar_config)


@pytest_asyncio.fixture(scope="function", autouse=True)
async def cleanup():
yield
async with base_ormar_config.database:
await Post.ormar_config.model_fields["categories"].through.objects.delete(
each=True
)
await Post.ormar_config.model_fields["authors"].through.objects.delete(
each=True
)
await Post.objects.delete(each=True)
await Category.objects.delete(each=True)
await Author.objects.delete(each=True)


@pytest.mark.asyncio
async def test_adding_same_m2m_model_twice():
async with base_ormar_config.database:
async with base_ormar_config.database.transaction(rollback=True):
async with base_ormar_config.database:
post = await Post.objects.create(title="Hello, M2M")
news = await Category(name="News").save()

Expand All @@ -69,7 +85,7 @@ async def test_adding_same_m2m_model_twice():
@pytest.mark.asyncio
async def test_adding_same_m2m_model_twice_with_unique():
async with base_ormar_config.database:
async with base_ormar_config.database.transaction(rollback=True):
async with base_ormar_config.database:
post = await Post.objects.create(title="Hello, M2M")
redactor = await Author(name="News").save()

Expand Down

0 comments on commit 1871aca

Please sign in to comment.