@@ -514,12 +514,17 @@ def _inject_setup_module_fixture(self) -> None:
514
514
Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with
515
515
other fixtures (#517).
516
516
"""
517
+ has_nose = self .config .pluginmanager .has_plugin ("nose" )
517
518
setup_module = _get_first_non_fixture_func (
518
519
self .obj , ("setUpModule" , "setup_module" )
519
520
)
521
+ if setup_module is None and has_nose :
522
+ setup_module = _get_first_non_fixture_func (self .obj , ("setup" ,))
520
523
teardown_module = _get_first_non_fixture_func (
521
524
self .obj , ("tearDownModule" , "teardown_module" )
522
525
)
526
+ if teardown_module is None and has_nose :
527
+ teardown_module = _get_first_non_fixture_func (self .obj , ("teardown" ,))
523
528
524
529
if setup_module is None and teardown_module is None :
525
530
return
@@ -750,13 +755,14 @@ def _call_with_optional_argument(func, arg) -> None:
750
755
func ()
751
756
752
757
753
- def _get_first_non_fixture_func (obj : object , names : Iterable [str ]):
758
+ def _get_first_non_fixture_func (obj : object , names : Iterable [str ]) -> Optional [ object ] :
754
759
"""Return the attribute from the given object to be used as a setup/teardown
755
760
xunit-style function, but only if not marked as a fixture to avoid calling it twice."""
756
761
for name in names :
757
- meth = getattr (obj , name , None )
762
+ meth : Optional [ object ] = getattr (obj , name , None )
758
763
if meth is not None and fixtures .getfixturemarker (meth ) is None :
759
764
return meth
765
+ return None
760
766
761
767
762
768
class Class (PyCollector ):
@@ -832,8 +838,17 @@ def _inject_setup_method_fixture(self) -> None:
832
838
Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with
833
839
other fixtures (#517).
834
840
"""
835
- setup_method = _get_first_non_fixture_func (self .obj , ("setup_method" ,))
836
- teardown_method = getattr (self .obj , "teardown_method" , None )
841
+ has_nose = self .config .pluginmanager .has_plugin ("nose" )
842
+ setup_name = "setup_method"
843
+ setup_method = _get_first_non_fixture_func (self .obj , (setup_name ,))
844
+ if setup_method is None and has_nose :
845
+ setup_name = "setup"
846
+ setup_method = _get_first_non_fixture_func (self .obj , (setup_name ,))
847
+ teardown_name = "teardown_method"
848
+ teardown_method = getattr (self .obj , teardown_name , None )
849
+ if teardown_method is None and has_nose :
850
+ teardown_name = "teardown"
851
+ teardown_method = getattr (self .obj , teardown_name , None )
837
852
if setup_method is None and teardown_method is None :
838
853
return
839
854
@@ -846,11 +861,11 @@ def _inject_setup_method_fixture(self) -> None:
846
861
def xunit_setup_method_fixture (self , request ) -> Generator [None , None , None ]:
847
862
method = request .function
848
863
if setup_method is not None :
849
- func = getattr (self , "setup_method" )
864
+ func = getattr (self , setup_name )
850
865
_call_with_optional_argument (func , method )
851
866
yield
852
867
if teardown_method is not None :
853
- func = getattr (self , "teardown_method" )
868
+ func = getattr (self , teardown_name )
854
869
_call_with_optional_argument (func , method )
855
870
856
871
self .obj .__pytest_setup_method = xunit_setup_method_fixture
0 commit comments