@@ -45,6 +45,57 @@ def pytest_configure(config):
4545 pass
4646
4747
48+ @pytest .fixture
49+ def clean_autopopulate (experiment , trial , ephys ):
50+ """
51+ Explicit cleanup fixture for autopopulate tests.
52+
53+ Cleans experiment/trial/ephys tables after test completes.
54+ Tests must explicitly request this fixture to get cleanup.
55+ """
56+ yield
57+ # Cleanup after test - delete in reverse dependency order
58+ ephys .delete ()
59+ trial .delete ()
60+ experiment .delete ()
61+
62+
63+ @pytest .fixture
64+ def clean_jobs (schema_any ):
65+ """
66+ Explicit cleanup fixture for jobs tests.
67+
68+ Cleans jobs table before test runs.
69+ Tests must explicitly request this fixture to get cleanup.
70+ """
71+ try :
72+ schema_any .jobs .delete ()
73+ except DataJointError :
74+ pass
75+ yield
76+
77+
78+ @pytest .fixture
79+ def clean_test_tables (test , test_extra , test_no_extra ):
80+ """
81+ Explicit cleanup fixture for relation tests using test tables.
82+
83+ Ensures test table has lookup data and restores clean state after test.
84+ Tests must explicitly request this fixture to get cleanup.
85+ """
86+ # Ensure lookup data exists before test
87+ if not test :
88+ test .insert (test .contents , skip_duplicates = True )
89+
90+ yield
91+
92+ # Restore original state after test
93+ test .delete ()
94+ test .insert (test .contents , skip_duplicates = True )
95+ test_extra .delete ()
96+ test_no_extra .delete ()
97+
98+
4899# Global container registry for cleanup
49100_active_containers = set ()
50101_docker_client = None
@@ -547,7 +598,7 @@ def mock_cache(tmpdir_factory):
547598 dj .config ["cache" ] = og_cache
548599
549600
550- @pytest .fixture
601+ @pytest .fixture ( scope = "module" )
551602def schema_any (connection_test , prefix ):
552603 schema_any = dj .Schema (
553604 prefix + "_test1" , schema .LOCALS_ANY , connection = connection_test
@@ -603,6 +654,63 @@ def schema_any(connection_test, prefix):
603654 schema_any .drop ()
604655
605656
657+ @pytest .fixture
658+ def schema_any_fresh (connection_test , prefix ):
659+ """Function-scoped schema_any for tests that need fresh schema state."""
660+ schema_any = dj .Schema (
661+ prefix + "_test1_fresh" , schema .LOCALS_ANY , connection = connection_test
662+ )
663+ assert schema .LOCALS_ANY , "LOCALS_ANY is empty"
664+ try :
665+ schema_any .jobs .delete ()
666+ except DataJointError :
667+ pass
668+ schema_any (schema .TTest )
669+ schema_any (schema .TTest2 )
670+ schema_any (schema .TTest3 )
671+ schema_any (schema .NullableNumbers )
672+ schema_any (schema .TTestExtra )
673+ schema_any (schema .TTestNoExtra )
674+ schema_any (schema .Auto )
675+ schema_any (schema .User )
676+ schema_any (schema .Subject )
677+ schema_any (schema .Language )
678+ schema_any (schema .Experiment )
679+ schema_any (schema .Trial )
680+ schema_any (schema .Ephys )
681+ schema_any (schema .Image )
682+ schema_any (schema .UberTrash )
683+ schema_any (schema .UnterTrash )
684+ schema_any (schema .SimpleSource )
685+ schema_any (schema .SigIntTable )
686+ schema_any (schema .SigTermTable )
687+ schema_any (schema .DjExceptionName )
688+ schema_any (schema .ErrorClass )
689+ schema_any (schema .DecimalPrimaryKey )
690+ schema_any (schema .IndexRich )
691+ schema_any (schema .ThingA )
692+ schema_any (schema .ThingB )
693+ schema_any (schema .ThingC )
694+ schema_any (schema .ThingD )
695+ schema_any (schema .ThingE )
696+ schema_any (schema .Parent )
697+ schema_any (schema .Child )
698+ schema_any (schema .ComplexParent )
699+ schema_any (schema .ComplexChild )
700+ schema_any (schema .SubjectA )
701+ schema_any (schema .SessionA )
702+ schema_any (schema .SessionStatusA )
703+ schema_any (schema .SessionDateA )
704+ schema_any (schema .Stimulus )
705+ schema_any (schema .Longblob )
706+ yield schema_any
707+ try :
708+ schema_any .jobs .delete ()
709+ except DataJointError :
710+ pass
711+ schema_any .drop ()
712+
713+
606714@pytest .fixture
607715def thing_tables (schema_any ):
608716 a = schema .ThingA ()
@@ -623,7 +731,7 @@ def thing_tables(schema_any):
623731 yield a , b , c , d , e
624732
625733
626- @pytest .fixture
734+ @pytest .fixture ( scope = "module" )
627735def schema_simp (connection_test , prefix ):
628736 schema = dj .Schema (
629737 prefix + "_relational" , schema_simple .LOCALS_SIMPLE , connection = connection_test
@@ -653,7 +761,7 @@ def schema_simp(connection_test, prefix):
653761 schema .drop ()
654762
655763
656- @pytest .fixture
764+ @pytest .fixture ( scope = "module" )
657765def schema_adv (connection_test , prefix ):
658766 schema = dj .Schema (
659767 prefix + "_advanced" ,
@@ -694,7 +802,7 @@ def schema_ext(
694802 schema .drop ()
695803
696804
697- @pytest .fixture
805+ @pytest .fixture ( scope = "module" )
698806def schema_uuid (connection_test , prefix ):
699807 schema = dj .Schema (
700808 prefix + "_test1" ,
0 commit comments