@@ -161,3 +161,158 @@ def test_c():
161161 "test_marker.py::test_a PASSED" ,
162162 ]
163163 )
164+
165+
166+ @pytest .mark .parametrize (
167+ "suffix, expected" ,
168+ [
169+ ("11" , ["test_b" , "test_a" ]),
170+ ("12" , ["test_b" , "test_a" ]),
171+ ("" , ["test_b" , "test_a" ]),
172+ ("1special" , ["test_b" , "test_a" ]),
173+ ("other" , ["test_b" , "test_a" ]),
174+ ("0" , ["test_a" , "test_b" ]),
175+ ],
176+ )
177+ def test_marker_prefix_uses_complete_numeric_suffix (test_path , suffix , expected ):
178+ test_path .makeini (
179+ f"""
180+ [pytest]
181+ console_output_style = classic
182+ markers =
183+ my{ suffix } : custom order
184+ my2: custom order
185+ """
186+ )
187+ test_path .makepyfile (
188+ test_marker = f"""
189+ import pytest
190+
191+ @getattr(pytest.mark, "my{ suffix } ")
192+ def test_a():
193+ pass
194+
195+ @pytest.mark.my2
196+ def test_b():
197+ pass
198+ """
199+ )
200+ result = test_path .runpytest ("-v" , "--order-marker-prefix=my" )
201+ result .assert_outcomes (passed = 2 )
202+ result .stdout .fnmatch_lines ([f"test_marker.py::{ name } PASSED" for name in expected ])
203+
204+
205+ def test_marker_prefix_supports_negative_indices (test_path ):
206+ test_path .makeini (
207+ """
208+ [pytest]
209+ console_output_style = classic
210+ markers =
211+ my-1: custom order
212+ my-2: custom order
213+ my2: custom order
214+ """
215+ )
216+ test_path .makepyfile (
217+ test_marker = """
218+ import pytest
219+
220+ @getattr(pytest.mark, "my-1")
221+ def test_a():
222+ pass
223+
224+ @getattr(pytest.mark, "my-2")
225+ def test_b():
226+ pass
227+
228+ def test_c():
229+ pass
230+
231+ @pytest.mark.my2
232+ def test_d():
233+ pass
234+ """
235+ )
236+ result = test_path .runpytest ("-v" , "--order-marker-prefix=my" )
237+ result .assert_outcomes (passed = 4 )
238+ result .stdout .fnmatch_lines (
239+ [
240+ "test_marker.py::test_d PASSED" ,
241+ "test_marker.py::test_c PASSED" ,
242+ "test_marker.py::test_b PASSED" ,
243+ "test_marker.py::test_a PASSED" ,
244+ ]
245+ )
246+
247+
248+ @pytest .mark .parametrize (
249+ "suffix, expected" ,
250+ [
251+ ("_neg1" , ["test_c" , "test_b" , "test_a" ]),
252+ ("neg1" , ["test_c" , "test_b" , "test_a" ]),
253+ ("_neg" , ["test_c" , "test_a" , "test_b" ]),
254+ ("neg-1" , ["test_c" , "test_a" , "test_b" ]),
255+ ("_negative1" , ["test_c" , "test_a" , "test_b" ]),
256+ ],
257+ )
258+ def test_marker_prefix_supports_neg_placeholder (test_path , suffix , expected ):
259+ test_path .makeini (
260+ f"""
261+ [pytest]
262+ console_output_style = classic
263+ markers =
264+ my{ suffix } : custom order
265+ my2: custom order
266+ """
267+ )
268+ test_path .makepyfile (
269+ test_marker = f"""
270+ import pytest
271+
272+ @getattr(pytest.mark, "my{ suffix } ")
273+ def test_a():
274+ pass
275+
276+ def test_b():
277+ pass
278+
279+ @pytest.mark.my2
280+ def test_c():
281+ pass
282+ """
283+ )
284+ result = test_path .runpytest ("-v" , "--order-marker-prefix=my" )
285+ result .assert_outcomes (passed = 3 )
286+ result .stdout .fnmatch_lines ([f"test_marker.py::{ name } PASSED" for name in expected ])
287+
288+
289+ @pytest .mark .parametrize ("suffix" , ["" , "0" , "11" , "1special" , "-1" , "_neg1" ])
290+ def test_explicit_order_overrides_marker_prefix (test_path , suffix ):
291+ test_path .makeini (
292+ f"""
293+ [pytest]
294+ console_output_style = classic
295+ markers =
296+ my{ suffix } : custom order
297+ my2: custom order
298+ """
299+ )
300+ test_path .makepyfile (
301+ test_marker = f"""
302+ import pytest
303+
304+ @pytest.mark.order(3)
305+ @getattr(pytest.mark, "my{ suffix } ")
306+ def test_a():
307+ pass
308+
309+ @pytest.mark.my2
310+ def test_b():
311+ pass
312+ """
313+ )
314+ result = test_path .runpytest ("-v" , "--order-marker-prefix=my" )
315+ result .assert_outcomes (passed = 2 )
316+ result .stdout .fnmatch_lines (
317+ ["test_marker.py::test_b PASSED" , "test_marker.py::test_a PASSED" ]
318+ )
0 commit comments