- 上篇博客介绍了allure集成在Jenkins,以及Jenkins构建本地job的方式.
- allure报告不会显示 @pytest.mark 标记的标记名称,这样不太方便阅读.
- 本篇博客介绍 allure 自带标记的方式,并可以将标记名称显示在报告中.
- BDD标记
@allure.feature
/@allure.story
- 优先级标记
@allure.severity(@allure.severity_level.[Severity])
- 自定义标记
- BDD标记
@allure.feature
@allure.story
@allure.feature('feature_1')
@allure.story('story_1')
def test_1(login):
print('*' * 5 + 'test_1' + '*' * 5)
a = 'hello world!'
assert 'hello' in a
@allure.story('story_2')
def test_2():
print('*' * 5 + 'test_2' + '*' * 5)
x = 'hello world!'
assert hasattr(x, 'helloWorld')
@allure.story('story_3')
def test_3():
print('*' * 5 + 'test_3' + '*' * 5)
b = 3
assert b == 4
- 报告中 feature by storys 栏目显示了 allure 标记
- show all 查看详情
- story 是 feature 的子集
- 测试用例会按照 allure 标记分类显示,报告层次更鲜明
- 是否可以用 allure 标记替代 @pytest.mark?
答案是肯定的,@pytest.mark可以指定运行的用例,allure标记同样也可以
--allure-features
--allure-stories
指定命令运行:
pytest test_demo_2.py --allure-features feature_1
也可以这样:pytest test_demo_2.py --allure-features feature_1 --allure-stories story_1
- 优先级标记
@allure.severity(@allure.severity_level.[Severity])
class Severity(str, Enum):
BLOCKER = 'blocker'
CRITICAL = 'critical'
NORMAL = 'normal'
MINOR = 'minor'
TRIVIAL = 'trivial'
@allure.severity(allure.severity_level.NORMAL)
def test_2():
print('*' * 5 + 'test_2' + '*' * 5)
x = 'hello world!'
assert hasattr(x, 'helloWorld')
@allure.severity(allure.severity_level.CRITICAL)
def test_3():
print('*' * 5 + 'test_3' + '*' * 5)
pass
- 执行代码
pytest -s . est_demo_2.py --allure-severities normal,critical --alluredir report