Ubuntu+Python3+allure环境搭建(适用于所有Linux系统搭建allure环境)
# 环境准备
首先确保当前系统下已安装了Python3和Java
my@mypc:~$ python3
Python 3.6.9 (default, Jul 17 2020, 12:50:27)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
my@mypc:~$ java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~18.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
my@mypc:~$ javac -version
javac 1.8.0_265
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 安装配置allure
# Github官方allure仓库下载allure二进制文件压缩包
下载地址:https://github.com/allure-framework/allure2/releases (opens new window)
# 将下载下来的压缩包解压缩到家(~)目录
# 进入家目录
cd ~
# 解压
unzip allure-2.13.6.zip
1
2
3
4
2
3
4
# 进入allure-2.13.6
目录下的bin
目录,为allure
创建软连接即可
# 进入allure-2.13.6目录下的bin目录
cd /home/my/allure-2.13.6/bin
# 创建软连接,需要root权限
sudo ln -s /home/my/allure-2.13.6/bin/allure /usr/bin/allure
# 验证allure是否安装配置成功
allure --version
1
2
3
4
5
6
2
3
4
5
6
# 使用allure生成测试报告
# 安装pytest
pip3 install -i https://pypi.douban.com/simple pytest
# 安装allure-pytest
pip3 install -i https://pypi.douban.com/simple allure-pytest
1
2
3
4
2
3
4
# 示例Demo
文件结构如下
# allure_demos是根目录,allure_files是空目录用来存放allure生成的数据文件
├── allure_demos
│ ├── allure_files
│ ├── __init__.py
│ └── test_cases_with_allure.py
1
2
3
4
5
2
3
4
5
test_cases_with_allure.py文件内容如下
# !/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2020/10/10 下午1:19
# @Author : passerby223
# @FileName : test_cases_with_allure.py
# @Description :
import pytest
def test_success():
"""this test succeeds"""
assert True
def test_failure():
"""this test fails"""
assert False
def test_skip():
"""this test is skipped"""
pytest.skip('for a reason!')
def test_broken():
raise Exception('oops')
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
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
要使Allure能够在测试执行期间收集测试结果,只需添加 --alluredir 选项,并提供指向应存储结果的文件夹的路径
my@mypc:~$ cd allure_demos/
# 生成测试报告所需数据文件并存放到allure_files文件夹下
my@mypc:~$ pytest --alluredir=allure_files
# 生成测试报告
my@mypc:~$ allure serve allure_files
Generating report to temp directory...
Report successfully generated to /tmp/652755770337899811/allure-report
Starting web server...
2020-10-10 13:28:35.879:INFO::main: Logging initialized @1452ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://127.0.1.1:41397/>. Press <Ctrl+C> to exit
正在现有的浏览器会话中打开。
[1010/132836.342200:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
执行完allure serve allure_files
后会启动一个web服务自动在默认浏览器中打开测试报告。
展示效果如下
编辑 (opens new window)
上次更新: 2023/01/04, 02:34:17
- 01
- Python实现对字符串的加解密02-25
- 02
- Python3对大文件中指定字符进行排序再写入到新的文件10-24
- 03
- Ubuntu下配置adb环境连接Android设备进行调试08-17