99This broke pytest fixtures that expected the DB to be ready after initializer().
1010
1111NOTE: These tests are skipped when running with pytest-xdist in parallel mode
12- AND in-memory SQLite, because in-memory SQLite creates a new DB per connection,
13- so create_db/drop_databases interferes with other tests on the same worker.
14- For persistent DBs (postgres, mysql, file-based sqlite), tests run normally.
15- For in-memory SQLite, run separately with: pytest tests/contrib/test_pytest_initializer.py -n0
12+ because create_db/drop_databases resets global Tortoise state (including event loop
13+ bindings on connections), which interferes with other tests on the same worker.
14+ Run them separately with: pytest tests/contrib/test_pytest_initializer.py -n0
1615"""
1716
1817import os
@@ -35,31 +34,16 @@ def get_test_db_url() -> str:
3534 return os .environ .get ("TORTOISE_TEST_DB" , "sqlite://:memory:" )
3635
3736
38- def is_memory_sqlite () -> bool :
39- """Check if we're using in-memory SQLite."""
40- return ":memory:" in get_test_db_url ()
41-
42-
4337def is_sqlite () -> bool :
4438 """Check if we're using SQLite (any variant)."""
4539 return get_test_db_url ().startswith ("sqlite:" )
4640
4741
48- def should_skip_initializer_tests () -> bool :
49- """
50- Skip these tests when running with xdist AND in-memory sqlite.
51-
52- The issue is that in-memory sqlite creates a new DB per connection,
53- so create_db/drop_databases interferes with other tests on the same worker.
54- For persistent DBs (postgres, mysql, file-sqlite), this isn't an issue.
55- """
56- return is_xdist_worker () and is_memory_sqlite ()
57-
58-
59- # Skip only when running with xdist AND in-memory sqlite
42+ # Skip when running with xdist - create_db/drop_databases resets global state
43+ # (including event loop bindings) which interferes with other tests on same worker
6044pytestmark = pytest .mark .skipif (
61- should_skip_initializer_tests (),
62- reason = "These tests use create_db which resets global state; with in-memory sqlite run separately with -n0" ,
45+ is_xdist_worker (),
46+ reason = "These tests use create_db which resets global state; run separately with -n0" ,
6347)
6448
6549
0 commit comments