Skip to content

Commit

Permalink
Improve test isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
henadzit committed Dec 18, 2024
1 parent 3aa4745 commit 8a9219f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tests/test_early_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Meta:
ordering = ["name"]


class TestBasic(test.TestCase):
class TestBasic(test.SimpleTestCase):
def test_early_init(self):
self.maxDiff = None
Event_TooEarly = pydantic_model_creator(Event)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_table_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ async def asyncSetUp(self):
)
await Tortoise.generate_schemas()

async def asyncTearDown(self):
await Tortoise.close_connections()

async def test_glabal_name_generator(self):
self.assertEqual(Tournament._meta.db_table, "test_tournament")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_two_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def asyncSetUp(self):

async def asyncTearDown(self) -> None:
await Tortoise._drop_databases()
await super(TestTwoDatabases, self).asyncTearDown()
await super().asyncTearDown()

async def test_two_databases(self):
tournament = await Tournament.create(name="Tournament")
Expand Down
13 changes: 5 additions & 8 deletions tests/utils/test_run_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
from unittest import skipIf

from tortoise import Tortoise, connections, run_async
from tortoise.contrib.test import TestCase
from tortoise.contrib.test import SimpleTestCase


@skipIf(os.name == "nt", "stuck with Windows")
class TestRunAsync(TestCase):
async def asyncSetUp(self) -> None:
pass

async def asyncTearDown(self) -> None:
pass

class TestRunAsync(SimpleTestCase):
def setUp(self):
self.somevalue = 1

def tearDown(self):
run_async(self.asyncTearDown())

async def init(self):
await Tortoise.init(db_url="sqlite://:memory:", modules={"models": []})
self.somevalue = 2
Expand Down
2 changes: 1 addition & 1 deletion tortoise/contrib/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def init_memory_sqlite(models: AsyncFunc) -> AsyncFunc: ...


def init_memory_sqlite(
models: Union[ModulesConfigType, AsyncFunc, None] = None
models: Union[ModulesConfigType, AsyncFunc, None] = None,
) -> Union[AsyncFunc, AsyncFuncDeco]:
"""
For single file style to run code with memory sqlite
Expand Down

0 comments on commit 8a9219f

Please sign in to comment.