1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
def test_multiple_markers(item_names_for):
test_content = """
import pytest
@pytest.mark.order(2)
def test_1():
pass
@pytest.mark.order(1)
@pytest.mark.order(3)
def test_2():
pass
"""
assert item_names_for(test_content) == [
"test_2[index=1]",
"test_1",
"test_2[index=3]",
]
def test_with_relative_markers(item_names_for):
test_content = """
import pytest
def test_1():
pass
@pytest.mark.order(before="test_1")
@pytest.mark.order(2)
def test_2():
pass
@pytest.mark.order(1)
@pytest.mark.order(before="test_1")
def test_3():
pass
@pytest.mark.order(-1)
@pytest.mark.order(-3)
def test_4():
pass
@pytest.mark.order(-2)
@pytest.mark.order(-4)
def test_5():
pass
"""
assert item_names_for(test_content) == [
"test_3[index=1]",
"test_2[index=2]",
"test_3[before=test_1]",
"test_2[before=test_1]",
"test_1",
"test_5[index=-4]",
"test_4[index=-3]",
"test_5[index=-2]",
"test_4[index=-1]",
]
def test_multiple_markers_with_parametrization(item_names_for):
test_content = """
import pytest
@pytest.mark.order(2)
def test_1():
pass
@pytest.mark.parametrize("arg", ["aaaaa", "bbbbb", "ccccc", "ddddd"])
@pytest.mark.order(1)
@pytest.mark.order(-1)
def test_2(arg):
pass
@pytest.mark.order(3)
def test_3():
pass
"""
assert item_names_for(test_content) == [
"test_2[index=1-aaaaa]",
"test_2[index=1-bbbbb]",
"test_2[index=1-ccccc]",
"test_2[index=1-ddddd]",
"test_1",
"test_3",
"test_2[index=-1-aaaaa]",
"test_2[index=-1-bbbbb]",
"test_2[index=-1-ccccc]",
"test_2[index=-1-ddddd]",
]
def test_multiple_markers_in_class(item_names_for):
test_content = """
import pytest
class TestA:
@pytest.mark.order(1)
@pytest.mark.order(3)
def test_1_and_3():
pass
@pytest.mark.order(-1)
def test_4():
pass
@pytest.mark.order(2)
def test_2():
pass
"""
assert item_names_for(test_content) == [
"TestA::test_1_and_3[index=1]",
"test_2",
"TestA::test_1_and_3[index=3]",
"TestA::test_4",
]
|