@@ -157,25 +157,30 @@ def pytest_generate_tests(metafunc):
157157
158158 Make parametrized tests with corresponding order marks.
159159 """
160- if getattr (metafunc , "function" , False ) and getattr (
161- metafunc .function , "pytestmark" , False
162- ):
160+ function = getattr (metafunc , "function" , None )
161+ if not function :
162+ return
163+ # The order marks are removed from the function below, so if the same
164+ # function is collected again (e.g. inherited by another test class or
165+ # imported into another module), the removed marks are taken from here
166+ order_marks = getattr (function , "_pytest_order_marks" , None )
167+ if order_marks is None :
163168 # Get list of order marks
164- marks = metafunc . function . pytestmark
169+ marks = getattr ( function , " pytestmark" , [])
165170 order_marks = [mark for mark in marks if mark .name == "order" ]
166171 if len (order_marks ) > 1 :
167172 # Remove all order marks
168- metafunc . function .pytestmark = [
169- mark for mark in marks if mark . name != "order"
170- ]
171- # Prepare arguments for parametrization with order marks
172- args = [
173- pytest .param (_get_mark_description (mark ), marks = [mark ])
174- for mark in order_marks
175- ]
176- if "order" not in metafunc .fixturenames :
177- metafunc .fixturenames .append ("order" )
178- metafunc .parametrize ("order" , args )
173+ function .pytestmark = [mark for mark in marks if mark . name != "order" ]
174+ function . _pytest_order_marks = order_marks
175+ if len ( order_marks ) > 1 :
176+ # Prepare arguments for parametrization with order marks
177+ args = [
178+ pytest .param (_get_mark_description (mark ), marks = [mark ])
179+ for mark in order_marks
180+ ]
181+ if "order" not in metafunc .fixturenames :
182+ metafunc .fixturenames .append ("order" )
183+ metafunc .parametrize ("order" , args )
179184
180185
181186@pytest .fixture
0 commit comments