@@ -519,8 +519,6 @@ def test_query_counter_ignores_particular_queries(self):
519
519
520
520
@requires_mongodb_gte_40
521
521
def test_updating_a_document_within_a_transaction (self ):
522
- connect ("mongoenginetest" )
523
-
524
522
class A (Document ):
525
523
name = StringField ()
526
524
@@ -538,8 +536,6 @@ class A(Document):
538
536
539
537
@requires_mongodb_gte_40
540
538
def test_updating_a_document_within_a_transaction_that_fails (self ):
541
- connect ("mongoenginetest" )
542
-
543
539
class A (Document ):
544
540
name = StringField ()
545
541
@@ -558,13 +554,16 @@ class A(Document):
558
554
559
555
@requires_mongodb_gte_40
560
556
def test_creating_a_document_within_a_transaction (self ):
561
- connect ("mongoenginetest" )
562
557
563
558
class A (Document ):
564
559
name = StringField ()
565
560
566
561
A .drop_collection ()
567
562
563
+ # ensure collection is created (needed for transaction with MongoDB <= 4.2)
564
+ A .objects .create (name = "test" )
565
+ A .objects .delete ()
566
+
568
567
with run_in_transaction ():
569
568
a_doc = A .objects .create (name = "a" )
570
569
another_doc = A (name = "b" ).save ()
@@ -578,12 +577,14 @@ class A(Document):
578
577
579
578
@requires_mongodb_gte_40
580
579
def test_creating_a_document_within_a_transaction_that_fails (self ):
581
- connect ("mongoenginetest" )
582
580
583
581
class A (Document ):
584
582
name = StringField ()
585
583
586
584
A .drop_collection ()
585
+ # ensure collection is created (needed for transaction with MongoDB <= 4.2)
586
+ A .objects .create (name = "test" )
587
+ A .objects .delete ()
587
588
588
589
with pytest .raises (TestRollbackError ):
589
590
with run_in_transaction ():
@@ -695,8 +696,6 @@ class B(Document):
695
696
696
697
@requires_mongodb_gte_40
697
698
def test_exception_in_child_of_a_nested_transaction_rolls_parent_back (self ):
698
- connect ("mongoenginetest" )
699
-
700
699
class A (Document ):
701
700
name = StringField ()
702
701
@@ -731,8 +730,6 @@ class B(Document):
731
730
def test_exception_in_parent_of_nested_transaction_after_child_completed_only_rolls_parent_back (
732
731
self ,
733
732
):
734
- connect ("mongoenginetest" )
735
-
736
733
class A (Document ):
737
734
name = StringField ()
738
735
@@ -772,7 +769,6 @@ def run_tx():
772
769
773
770
@requires_mongodb_gte_40
774
771
def test_nested_transactions_create_and_release_sessions_accordingly (self ):
775
- connect ("mongoenginetest" )
776
772
with run_in_transaction ():
777
773
s1 = _get_session ()
778
774
with run_in_transaction ():
@@ -808,7 +804,6 @@ def test_thread_safety_of_transactions(self):
808
804
809
805
0 + 10 + 2 + 30 + 4 + 50 + 6 + 70 + 8 + 90 = 270
810
806
"""
811
- connect ("mongoenginetest" )
812
807
813
808
class A (Document ):
814
809
i = IntField (unique = True )
0 commit comments