@@ -828,3 +828,64 @@ def test_should_not_run(self):
828
828
""" )
829
829
reprec = testdir .inline_run ()
830
830
reprec .assertoutcome (passed = 1 )
831
+
832
+
833
+ @pytest .mark .issue (3498 )
834
+ @pytest .mark .parametrize ("base" , [
835
+ 'six.moves.builtins.object' ,
836
+ 'unittest.TestCase' ,
837
+ 'unittest2.TestCase' ,
838
+ ])
839
+ def test_usefixtures_marker_on_unittest (base , testdir ):
840
+ module = base .rsplit ('.' , 1 )[0 ]
841
+ pytest .importorskip (module )
842
+ testdir .makepyfile (conftest = """
843
+ import pytest
844
+
845
+ @pytest.fixture(scope='function')
846
+ def fixture1(request, monkeypatch):
847
+ monkeypatch.setattr(request.instance, 'fixture1', True )
848
+
849
+
850
+ @pytest.fixture(scope='function')
851
+ def fixture2(request, monkeypatch):
852
+ monkeypatch.setattr(request.instance, 'fixture2', True )
853
+
854
+ def node_and_marks(item):
855
+ print(item.nodeid)
856
+ for mark in item.iter_markers():
857
+ print(" ", mark)
858
+
859
+ @pytest.fixture(autouse=True)
860
+ def my_marks(request):
861
+ node_and_marks(request.node)
862
+
863
+ def pytest_collection_modifyitems(items):
864
+ for item in items:
865
+ node_and_marks(item)
866
+
867
+ """ )
868
+
869
+ testdir .makepyfile ("""
870
+ import pytest
871
+ import {module}
872
+
873
+ class Tests({base}):
874
+ fixture1 = False
875
+ fixture2 = False
876
+
877
+ @pytest.mark.usefixtures("fixture1")
878
+ def test_one(self):
879
+ assert self.fixture1
880
+ assert not self.fixture2
881
+
882
+ @pytest.mark.usefixtures("fixture1", "fixture2")
883
+ def test_two(self):
884
+ assert self.fixture1
885
+ assert self.fixture2
886
+
887
+
888
+ """ .format (module = module , base = base ))
889
+
890
+ result = testdir .runpytest ('-s' )
891
+ result .assert_outcomes (passed = 2 )
0 commit comments