Skip to content

Commit d282b0c

Browse files
committed
added decorators for restricting tests to certain engines
1 parent afa8470 commit d282b0c

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ dist/
1212
piccolo.sqlite
1313
_build/
1414
.coverage
15+
*.sqlite

piccolo/engine/finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import typing as t
55
import warnings
66

7-
from .base import Engine
7+
from piccolo.engine.base import Engine
88

99

1010
DEFAULT_MODULE_NAME = "piccolo_conf"

test.sqlite

-20 KB
Binary file not shown.

tests/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import asyncio
22
from unittest import TestCase
33

4+
import pytest
5+
46
from piccolo.engine.finder import engine_finder
7+
from piccolo.engine.postgres import PostgresEngine
8+
from piccolo.engine.sqlite import SQLiteEngine
59

610

711
ENGINE = engine_finder()
812

913

14+
postgres_only = pytest.mark.skipif(
15+
not isinstance(ENGINE, PostgresEngine), reason="Only running for Postgres"
16+
)
17+
18+
19+
sqlite_only = pytest.mark.skipif(
20+
not isinstance(ENGINE, SQLiteEngine), reason="Only running for SQLite"
21+
)
22+
23+
1024
class DBTestCase(TestCase):
1125
"""
1226
Using raw SQL, otherwise tests are too reliant on other Piccolo code.

tests/engine/test_pool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
from unittest import TestCase
44

5-
from ..base import DBTestCase
5+
from ..base import DBTestCase, postgres_only
66
from ..example_project.tables import Manager
77

88

9+
@postgres_only
910
class TestPool(DBTestCase):
1011
async def create_pool(self):
1112
await Manager.Meta.db.start_connnection_pool()

tests/engine/test_transaction.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from unittest import TestCase
22

33
from ..example_project.tables import Band, Manager
4+
from ..base import postgres_only
45

56

7+
@postgres_only
68
class TestTransaction(TestCase):
7-
89
def test_error(self):
910
"""
1011
Make sure queries in a transaction aren't committed if a query fails.
@@ -13,36 +14,22 @@ def test_error(self):
1314
transaction.add(
1415
Manager.create(),
1516
Band.create(),
16-
Band.raw('MALFORMED QUERY ... SHOULD ERROR')
17+
Band.raw("MALFORMED QUERY ... SHOULD ERROR"),
1718
)
1819
try:
1920
transaction.run_sync()
2021
except Exception:
2122
pass
22-
self.assertTrue(
23-
not Band.table_exists().run_sync()
24-
)
25-
self.assertTrue(
26-
not Manager.table_exists().run_sync()
27-
)
23+
self.assertTrue(not Band.table_exists().run_sync())
24+
self.assertTrue(not Manager.table_exists().run_sync())
2825

2926
def test_succeeds(self):
3027
transaction = Band.Meta.db.transaction()
31-
transaction.add(
32-
Manager.create(),
33-
Band.create()
34-
)
28+
transaction.add(Manager.create(), Band.create())
3529
transaction.run_sync()
3630

37-
self.assertTrue(
38-
Band.table_exists().run_sync()
39-
)
40-
self.assertTrue(
41-
Manager.table_exists().run_sync()
42-
)
31+
self.assertTrue(Band.table_exists().run_sync())
32+
self.assertTrue(Manager.table_exists().run_sync())
4333

44-
transaction.add(
45-
Band.drop(),
46-
Manager.drop()
47-
)
34+
transaction.add(Band.drop(), Manager.drop())
4835
transaction.run_sync()

0 commit comments

Comments
 (0)