2
2
3
3
import contextlib
4
4
import os
5
+ import platform
5
6
import shlex
6
7
import shutil
7
8
import subprocess
12
13
from tests ._utils import Dialect , chdir , copy_files
13
14
14
15
15
- def run_aerich (cmd : str ) -> None :
16
- with contextlib . suppress ( subprocess . TimeoutExpired ):
17
- if not cmd .startswith ("aerich" ) and not cmd . startswith ( "poetry" ) :
16
+ def run_aerich (cmd : str ) -> subprocess . CompletedProcess | None :
17
+ if not cmd . startswith ( "poetry" ) and not cmd . startswith ( "python" ):
18
+ if not cmd .startswith ("aerich" ):
18
19
cmd = "aerich " + cmd
19
- subprocess .run (shlex .split (cmd ), timeout = 2 )
20
+ if platform .system () == "Windows" :
21
+ cmd = "python -m " + cmd
22
+ r = None
23
+ with contextlib .suppress (subprocess .TimeoutExpired ):
24
+ r = subprocess .run (shlex .split (cmd ), timeout = 2 )
25
+ return r
20
26
21
27
22
28
def run_shell (cmd : str ) -> subprocess .CompletedProcess :
@@ -43,6 +49,15 @@ def prepare_sqlite_project(tmp_path: Path) -> Generator[tuple[Path, str]]:
43
49
yield models_py , models_py .read_text ("utf-8" )
44
50
45
51
52
+ def test_close_tortoise_connections_patch (tmp_path : Path ) -> None :
53
+ if not Dialect .is_sqlite ():
54
+ return
55
+ with prepare_sqlite_project (tmp_path ) as (models_py , models_text ):
56
+ run_aerich ("aerich init -t settings.TORTOISE_ORM" )
57
+ r = run_aerich ("aerich init-db" )
58
+ assert r is not None
59
+
60
+
46
61
def test_sqlite_migrate_alter_indexed_unique (tmp_path : Path ) -> None :
47
62
if not Dialect .is_sqlite ():
48
63
return
0 commit comments