Pytest集成Allure Report

news2024/9/22 5:22:25

目录

 

安装

用法

基本报告

支持 Pytest features

Xfail

条件标记

Fixtures and Finalizers

参数化

Allure Features

Steps

附件

描述

标题

重试

Tags

BDD 标签

严重性标记

Behave

安装

 使用

 Features

严重性

步骤和场景状态

步骤数据


安装


Pytest可从PyPI进行安装,因此建议使用pip进行安装。要安装最新版本,请从命令行执行:
 

$ pip install allure-pytest


这将安装allure pytest和allure python-commons包,以生成与allure2兼容的报告数据。如果第一代allure 报告使用的是以前版本的适配器,则需要首先卸载它。

用法

要使Allure侦听器能够在测试执行期间收集结果,只需添加--alluredir选项并提供应存储结果的文件夹的路径。例如:

$ pytest --alluredir=/tmp/my_allure_results

要在测试完成后查看实际报告,您需要使用Allure命令行实用程序根据结果生成报告。

$ allure serve /tmp/my_allure_results

此命令将在默认浏览器中显示生成的报告。

基本报告

您可以在Allure报告中看到所有默认的pytest状态:只有由于其中一个断言错误而未成功的测试才会被标记为失败,任何其他异常都会导致测试处于中断状态。

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')

支持 Pytest features

Allure报告支持的一些常见Pytest特性包括xfail、fixture和finalizer、标记、条件跳过和参数化。

Xfail


这是标记预期失败的pytest方法:(pytest文档)

@pytest.mark.xfail(condition=lambda: True, reason='this test is expecting failure')
def test_xfail_expected_failure():
    """this test is an xfail that will be marked as expected failure"""
    assert False


@pytest.mark.xfail(condition=lambda: True, reason='this test is expecting failure')
def test_xfail_unexpected_pass():
    """this test is an xfail that will be marked as unexpected success"""
    assert True

这导致测试被跳过,并在预期失败时用特殊标记进行标记。

以及描述中的特殊标记和意外通过时的特殊标签。

条件标记

在Pytest中,您可以有条件地将测试标记为在某些特定条件下不执行(Pytest docs):

@pytest.mark.skipif('2 + 2 != 5', reason='This test is skipped by a triggered condition in @pytest.mark.skipif')
def test_skip_by_triggered_condition():
    pass

当条件求值为true时,测试将在报告中接收“Skipped”状态、来自装饰器的标记和描述。

Fixtures and Finalizers

fixture和finalizer是Pytest将分别在测试开始前和测试结束后调用的实用函数。Allure跟踪每个fixture的调用,并详细显示调用了哪些方法和哪些参数,从而保留了正确的调用顺序。 (Pytest docs)

您不需要标记您的固定装置以使其在报告中可见,它们将自动检测到不同的skope。

@pytest.fixture(params=[True, False], ids=['param_true', 'param_false'])
def function_scope_fixture_with_finalizer(request):
    if request.param:
        print('True')
    else:
        print('False')
    def function_scope_finalizer():
        function_scope_step()
    request.addfinalizer(function_scope_finalizer)


@pytest.fixture(scope='class')
def class_scope_fixture_with_finalizer(request):
    def class_finalizer_fixture():
        class_scope_step()
    request.addfinalizer(class_finalizer_fixture)


@pytest.fixture(scope='module')
def module_scope_fixture_with_finalizer(request):
    def module_finalizer_fixture():
        module_scope_step()
    request.addfinalizer(module_finalizer_fixture)


@pytest.fixture(scope='session')
def session_scope_fixture_with_finalizer(request):
    def session_finalizer_fixture():
        session_scope_step()
    request.addfinalizer(session_finalizer_fixture)


class TestClass(object):

    def test_with_scoped_finalizers(self,
                                    function_scope_fixture_with_finalizer,
                                    class_scope_fixture_with_finalizer,
                                    module_scope_fixture_with_finalizer,
                                    session_scope_fixture_with_finalizer):
        step_inside_test_body()

根据夹具执行的结果,依赖它的测试可能会收到不同的状态。fixture中的异常将使所有依赖测试中断,pytest.skip()调用将使所有从属测试跳过。

import pytest

@pytest.fixture
def skip_fixture():
    pytest.skip()


@pytest.fixture
def fail_fixture():
    assert False


@pytest.fixture
def broken_fixture():
    raise Exception("Sorry, it's broken.")


def test_with_pytest_skip_in_the_fixture(skip_fixture):
    pass


def test_with_failure_in_the_fixture(fail_fixture):
    pass


def test_with_broken_fixture(broken_fixture):
    pass

参数化

您可以使用从输入参数集生成许多测试用例 @pytest.mark.parametrize. (Pytest docs)

所有参数名称和值都将在报告中捕获,也可以选择将参数名称替换为ids kwarg中提供的字符串描述。

import allure
import pytest


@allure.step
def simple_step(step_param1, step_param2 = None):
    pass


@pytest.mark.parametrize('param1', [True, False], ids=['id explaining value 1', 'id explaining value 2'])
def test_parameterize_with_id(param1):
    simple_step(param1)


@pytest.mark.parametrize('param1', [True, False])
@pytest.mark.parametrize('param2', ['value 1', 'value 2'])
def test_parametrize_with_two_parameters(param1, param2):
    simple_step(param1, param2)


@pytest.mark.parametrize('param1', [True], ids=['boolean parameter id'])
@pytest.mark.parametrize('param2', ['value 1', 'value 2'])
@pytest.mark.parametrize('param3', [1])
def test_parameterize_with_uneven_value_sets(param1, param2, param3):
    simple_step(param1, param3)
    simple_step(param2)

使用不同的命名和未命名参数集捕获的测试调用的示例。

具有命名参数的参数化测试的测试执行详细信息。

Allure Features

Allure目前几乎支持所有可用的功能,除了Pytest环境。

Steps

Allure报告的第一个可能也是最重要的方面是,它允许获得每个测试调用的非常详细的逐步表示。通过@allure.step decorator可以实现这一点,该decorator向报告添加了对带有所提供参数的注释方法或函数的调用。
用@step注释的方法可以存储在测试之外,并在需要时导入。步骤方法可以具有任意深度的嵌套结构。

import allure
import pytest

from .steps import imported_step


@allure.step
def passing_step():
    pass


@allure.step
def step_with_nested_steps():
    nested_step()


@allure.step
def nested_step():
    nested_step_with_arguments(1, 'abc')


@allure.step
def nested_step_with_arguments(arg1, arg2):
    pass


def test_with_imported_step():
    passing_step()
    imported_step()


def test_with_nested_steps():
    passing_step()
    step_with_nested_steps()

每个步骤的状态都显示在名称右侧的一个小图标中。嵌套步骤以树状可折叠结构进行组织。

步骤可以有一个描述行,该行支持传递的位置参数和关键字参数的占位符。关键字参数的默认参数也将被捕获。

import allure

@allure.step('Step with placeholders in the title, positional: "{0}", keyword: "{key}"')
def step_with_title_placeholders(arg1, key=None):
    pass


def test_steps_with_placeholders():
    step_with_title_placeholders(1, key='something')
    step_with_title_placeholders(2)
    step_with_title_placeholders(3, 'anything')

台阶也由固定装置支撑。下面是一个使用conftest.py模块中定义的fixture的测试示例(即使不直接导入,这样的fixture也会由Pytest解析):

conftest.py

import allure
import pytest


@allure.step('step in conftest.py')
def conftest_step():
    pass


@pytest.fixture
def fixture_with_conftest_step():
    conftest_step()
import allure

from .steps import imported_step


@allure.step
def passing_step():
    pass


def test_with_step_in_fixture_from_conftest(fixture_with_conftest_step):
    passing_step()

固定装置中的步骤显示在单独的树中,用于setup和teardown。

附件

报告可以显示提供的许多不同类型的附件,这些附件可以补充测试、步骤或夹具结果。附件可以通过调用诱惑来创建。attach(body,name,attachment_type,extension):

  1. body - 要写入文件的原始内容。

  2. name - 包含文件名的字符串

  3. attachment_type -attachment_type-allure.attachment_type值之一

  4. extension - 扩展名-将被用作创建文件的扩展名。

或allure.attach.file(源、名称、附件类型、扩展名):

  1. source - 包含文件路径的字符串。

(其他参数类似)

import allure
import pytest


@pytest.fixture
def attach_file_in_module_scope_fixture_with_finalizer(request):
    allure.attach('A text attacment in module scope fixture', 'blah blah blah', allure.attachment_type.TEXT)
    def finalizer_module_scope_fixture():
        allure.attach('A text attacment in module scope finalizer', 'blah blah blah blah',
                      allure.attachment_type.TEXT)
    request.addfinalizer(finalizer_module_scope_fixture)


def test_with_attacments_in_fixture_and_finalizer(attach_file_in_module_scope_finalizer):
    pass


def test_multiple_attachments():
    allure.attach.file('./data/totally_open_source_kitten.png', attachment_type=allure.attachment_type.PNG)
    allure.attach('<head></head><body> a page </body>', 'Attach with HTML type', allure.attachment_type.HTML)

附件显示在所属测试实体的上下文中。HTML类型的附件呈现并显示在报告页面上。这是一种方便的方式,可以为您自己的测试结果表示提供一些自定义。

描述

您可以添加测试的详细描述,以便根据需要为报表读取器提供尽可能多的上下文。这可以通过几种方式实现:您可以添加一个提供描述字符串的@allure.description装饰器,也可以使用@allre.description_html提供一些要在测试用例的“描述”部分中呈现的html。或者,描述将简单地从测试方法的文档字符串中提取。

import allure

@allure.description_html("""
<h1>Test with some complicated html description</h1>
<table style="width:100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
  </tr>
  <tr align="center">
    <td>William</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr align="center">
    <td>Vasya</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
</table>
""")
def test_html_description():
    assert True


@allure.description("""
Multiline test description.
That comes from the allure.description decorator.

Nothing special about it.
""")
def test_description_from_decorator():
    assert 42 == int(6 * 7)


def test_unicode_in_docstring_description():
    """Unicode in description.

    Этот тест проверяет юникод.

    你好伙计.
    """
    assert 42 == int(6 * 7)

描述支持unicode字符串:

从description_HTML呈现的HTML:

此外,可以使用allure.dynamic.description从测试体内动态更新描述。

import allure

@allure.description("""
This description will be replaced at the end of the test.
""")
def test_dynamic_description():
    assert 42 == int(6 * 7)
    allure.dynamic.description('A final description.')
标题

使用特殊的@allure.title装饰器可以使测试标题更具可读性。标题支持参数占位符,并支持动态替换。

import allure
import pytest


@allure.title("This test has a custom title")
def test_with_a_title():
    assert 2 + 2 == 4


@allure.title("This test has a custom title with unicode: Привет!")
def test_with_unicode_title():
    assert 3 + 3 == 6


@allure.title("Parameterized test title: adding {param1} with {param2}")
@pytest.mark.parametrize('param1,param2,expected', [
    (2, 2, 4),
    (1, 2, 5)
])
def test_with_parameterized_title(param1, param2, expected):
    assert param1 + param2 == expected


@allure.title("This title will be replaced in a test body")
def test_with_dynamic_title():
    assert 2 + 2 == 4
    allure.dynamic.title('After a successful test finish, the title was replaced with this line.')

要将报告与错误跟踪器或测试管理系统集成,Allure具有@Allure.link、@Allure.issue和@Allure.testcase描述符。

import allure

TEST_CASE_LINK = 'https://github.com/qameta/allure-integrations/issues/8#issuecomment-268313637'


@allure.link('https://www.youtube.com/watch?v=4YYzUTYZRMU')
def test_with_link():
    pass


@allure.link('https://www.youtube.com/watch?v=Su5p2TqZxKU', name='Click me')
def test_with_named_link():
    pass


@allure.issue('140', 'Pytest-flaky test retries shows like test steps')
def test_with_issue_link():
    pass


@allure.testcase(TEST_CASE_LINK, 'Test case title')
def test_with_testcase_link():
    pass

@allure.link将在“链接”部分提供指向所提供url的可点击链接:

@allure.issue将提供一个带有小错误图标的链接。此描述符将测试用例id作为输入参数,以便将其与所提供的问题链接类型的链接模板一起使用。链接模板在Pytest的--plure链接模式配置选项中指定。必须使用冒号指定链接模板和类型:

$ pytest directory_with_tests/ --alluredir=/tmp/my_allure_report \
 --allure-link-pattern=issue:http://www.mytesttracker.com/issue/{}

模板关键字是issue、link和test_case,为相应类型的链接提供模板。

重试


诱惑允许您聚合关于在单个测试运行期间重新执行的测试的信息,以及一段时间内测试执行的历史记录。
对于重试,您可以使用Pytest重新运行失败插件。
例如,如果我们有一个非常不可靠的步骤方法,但经常失败,在Pytest启动选项中指定--reruns=5后,我们会在Retries选项卡上显示所有运行此测试的失败尝试。

import allure
import random
import time


@allure.step
def passing_step():
    pass


@allure.step
def flaky_broken_step():
    if random.randint(1, 5) != 1:
        raise Exception('Broken!')


def test_broken_with_randomized_time():
    passing_step()
    time.sleep(random.randint(1, 3))
    flaky_broken_step()

同样,这样的测试会在执行的测试列表中收到“片状”炸弹图标。

Tags

有时,您希望能够灵活地处理要执行的测试。Pytest通过使用标记decorator@Pytest.mark(Pytest文档)来实现这一点。

Allure允许使用3种类型的标记装饰器以类似的方式标记测试,这些标记装饰器允许构建报告的表示:

  1. BDD风格的标记表示史诗、特色和故事

  2. 严重性标签

  3. 自定义标签

BDD 标签


有两个装饰器:@allure.feature和@allure.story,用于根据您项目的功能/故事细分来标记您的测试(有关背景信息,请参阅维基百科上的BDD文章)。要标记某个特征或故事属于史诗,请使用以epic_前缀开头的名称。
 

tests.py

import allure


def test_without_any_annotations_that_wont_be_executed():
    pass


@allure.story('epic_1')
def test_with_epic_1():
    pass


@allure.story('story_1')
def test_with_story_1():
    pass

@allure.story('story_2')
def test_with_story_2():
    pass


@allure.feature('feature_2')
@allure.story('story_2')
def test_with_story_2_and_feature_2():
    pass

您可以使用以下命令行选项指定要执行的不同测试集,并传递逗号分隔的值列表:

  1. --allure-epics

  2. --allure-features

  3. --allure-stories

例如:

$ pytest tests.py --allure-stories story_1,story_2

collected 5 items

tests.py ...                                                                    [100%]

============================== 3 passed in 0.01 seconds ==============================
$ pytest tests.py --allure-features feature2 --allure-stories story2

collected 5 items

tests.py ...                                                                     [100%]

=============================== 2 passed in 0.01 seconds ==============================
严重性标记

要按严重性级别标记测试,可以使用@allure.severity decorator。它以allure.severity_level枚举值为参数。

tests.py

import allure


def test_with_no_severity_label():
    pass


@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_severity():
    pass


@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_severity():
    pass


@allure.severity(allure.severity_level.NORMAL)
class TestClassWithNormalSeverity(object):

    def test_inside_the_normal_severity_test_class(self):
        pass

    @allure.severity(allure.severity_level.CRITICAL)
    def test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self):
        pass

Severity decorator可以应用于函数、方法或整个类。
通过使用带有逗号分隔的严重性级别列表的--plure severties命令行选项,将只运行具有相应严重性的测试。

$ pytest tests.py --allure-severities normal,critical

collected 5 items

bdd_annotations_demo/test_severity_labels.py ...                                [100%]

================================ 3 passed in 0.01 seconds ============================

Behave

诱惑与behavior集成为一个外部格式化程序。

安装

$ pip install allure-behave

 使用

您可以直接在命令行中指定格式化程序:

$ behave -f allure_behave.formatter:AllureFormatter -o %allure_result_folder% ./features

 Features

严重性

与严重性名称匹配的标签(如关键、琐碎等)将被解释为功能或场景严重性。如果没有提供,场景将继承功能严重性,或者在其他情况下覆盖它。如果存在多个严重性定义标记,则只使用最后一个。

步骤和场景状态

具有断言异常的步骤将被标记为失败。在测试执行过程中引发的其他异常将导致其状态被破坏。场景状态将由第一个不成功的步骤状态决定。当所有步骤都通过了,那么整个场景就被认为通过了。

步骤数据

步骤数据文本或表格数据在报告中表示为步骤附件

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/675150.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot 如何使用 @RequestBody 进行数据校验

SpringBoot 如何使用 RequestBody 进行数据校验 在 Web 开发中&#xff0c;前台向后台发送数据是非常常见的场景。而在 SpringBoot 框架中&#xff0c;我们通常使用 RequestBody 注解来接收前台发送的 JSON 数据&#xff0c;并将其转化为 Java 对象。但是&#xff0c;接收到的…

你一定想知道的 如何进行动态内存管理?

文章目录 引言malloc函数calloc函数realloc函数free函数-避免内存泄漏常见的动态内存错误 引言 如果我们被问道&#xff1a;如何创建一个可以根据用户需求来开辟大小的数组&#xff1f; 可能有些博友会写出如下代码&#xff1a; #include <stdio.h> int main() {int n…

c++11 标准模板(STL)(std::basic_streambuf)(二)

定义于头文件 <streambuf> template< class CharT, class Traits std::char_traits<CharT> > class basic_streambuf; 类 basic_streambuf 控制字符序列的输入与输出。它包含下列内容并提供到它们的访问&#xff1a; 1) 受控制字符序列&#xff…

专项练习9

目录 一、选择题 1、在 JavaScript 中&#xff0c;用于阻止默认事件的默认操作的方法是 2、以下代码执行后&#xff0c;result 的值为&#xff08;&#xff09; 3、不能从字符串 const str qwbewrbbeqqbbbweebbbbqee;中能得到结果 ["b", "bb", "bbb…

实时在线云消费机、考勤门禁控制器、网络读卡器服务端C# Socket源码

消费机UDP通讯协议介绍&#xff1a; 设备向服务器发送的指令格式&#xff0c;每个字段用半角逗号(,)分隔。序号指令名称指令格式指令说明示例1响应服务器的搜索100,包序列号,终端IP,子网掩码,网关IP,远程电脑主机IP,端口号,终端硬件号响应电脑发出的搜寻局域网内所有终端设备指…

【Python 基础篇】Python 异常处理

文章目录 引言一、Python异常概述二、常见的内置异常三、异常处理语句四、异常捕获和处理五、实例演示六、总结 引言 在软件开发中&#xff0c;错误和异常是难以避免的。当我们编写Python代码时&#xff0c;有时候会遇到各种各样的问题&#xff0c;例如无效的输入、文件不存在…

hello算法笔记之树

一、二叉树 与链表类似&#xff0c;二叉树的基本单元是节点&#xff0c;每个节点包含一个「值」和两个「指针」。 在二叉树中&#xff0c;除叶节点外&#xff0c;其他所有节点都包含子节点和非空子树。 一些术语&#xff1a; 「根节点 Root Node」&#xff1a;位于二叉树顶…

VNC虚拟网络控制台(概述、windows系统连接linux系统演示)

第三阶段基础 时 间&#xff1a;2023年6月22日 参加人&#xff1a;全班人员 内 容&#xff1a; VNC虚拟网络控制台 目录 一、VNC概述 二、VNC基本上是由两部分组成 三、VNC特点 四、工作流程 五、安装 六、操作演示Windiws10系统远程控制linux 服务端&#xff1a;…

window版安装kafka并提供启动快捷脚本

kafka下载地址&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1DpcGXvpTYAcG_fvS-p9-3g?pwd1234 提取码&#xff1a;1234 官网&#xff1a;https://kafka.apache.org/downloads 注意不需要单独安装zk&#xff0c;里面包括zk Kafka解压包目录不要太深了&#xff0c…

养老院人员跌倒检测识别算法

养老院人员跌倒检测识别预警系统通过yolov5python网络模型技术&#xff0c;养老院人员跌倒检测识别预警算法对跌倒事件进行识别和分析&#xff0c;当检测到有人员跌倒时&#xff0c;将自动发出警报提示相关人员及时采取措施。YOLOv5是一种单阶段目标检测算法&#xff0c;该算法…

CTF-Show密码学【Base64、栅栏密码、16进制】

题目内容 密文&#xff1a;53316C6B5A6A42684D3256695A44566A4E47526A4D5459774C5556375A6D49324D32566C4D4449354F4749345A6A526B4F48303D 提交格式&#xff1a;KEY{XXXXXXXXXXXXXX}工具下载&#xff1a;https://www.lanzoui.com/i9fn2aj萌新_密码13 分析和解决过程 初步分析…

【Python 基础篇】Python 面向对象编程:理解与实践

文章目录 一、引言二、类与对象三、封装与访问控制四、继承与多态&#xff08;第一部分&#xff09;五、方法重写与多态&#xff08;第二部分&#xff09;六、抽象类与接口1、抽象类2、接口 七、类的关联与组合1、关联关系2、组合关系 八、面向对象设计原则1、SOLID原则2、设计…

实验 4:排序与查找

东莞理工的学生可以借鉴&#xff0c;请勿抄袭 1.实验目的 通过实验达到&#xff1a; 理解典型排序的基本思想&#xff0c;掌握典型排序方法的思想和相应实现算法&#xff1b; 理解和掌握用二叉排序树(BST)实现动态查找的基本思想和相应的实现 算法。 理解和掌握哈希(HASH)存…

【备战秋招】每日一题:2023.04.26-实习-第三题-MC方块

在线评测链接:P1231 题目内容 MC最新版本更新了一种特殊的方块&#xff0c;幽匿催发体。这种方块能够吸收生物死亡掉落的经验并感染周围方块&#xff0c;使其变成幽匿块。Steve想要以此为基础尝试搭建一个经验仓库&#xff0c;他来到了创造超平坦模式&#xff0c;在只有草方块…

[进阶]junit单元测试框架详解

单元测试 就是针对最小的功能单元(方法&#xff09;&#xff0c;编写测试代码对其进行正确性测试。 以前是如何进行单元测试的&#xff1f;有什么问题&#xff1f; 只能在main方法编写测试代码&#xff0c;去调用其他方法进行测试。无法实现自动化测试&#xff0c;一个方法测…

python数字猜谜2.0

改进了一下数字猜谜&#xff1a; 开头&#xff0c;可选等级&#xff1a; import random guess -1 c 0 print("数字猜谜游戏&#xff01;") n input("选择等级 A B C&#xff1a;") if (n "A") or (n "a"):guess random.randint…

模拟电路系列分享-阻容的频率响应

目录 概要 整体架构流程 技术名词解释 技术细节 1.以低通为例 2.高通电路&#xff1a; 总结&#xff1a; 概要 提示&#xff1a;这里可以添加技术概要 接着上一节的内容&#xff0c;这一节我们将介绍阻容的频率响应 整体架构流程 提示&#xff1a;这里可以添加技术整体架构…

模拟电路系列文章-放大电路输出电容

目录 概要 整体架构流程 技术名词解释 技术细节 小结 概要 提示&#xff1a;这里可以添加技术概要 一个运放组成的同相比例器&#xff08;包含运放内部结构&#xff09;所示&#xff0c;在它的输出端对地接了一个大电容C&#xff0c;这是一个极其危险的电路&#xff0c;一般会…

Java注解以及BigInteger类、BigDecimal类

说明&#xff1a; ① java.math包的BigInteger可以表示不可变的任意精度的整数。 ② 要求数字精度比较高&#xff0c;用到java.math.BigDecimal类 15是精度 后面大写的字母是要求要四舍五入 注解的理解 ① jdk 5.0 新增的功能 ② Annotation 其实就是代码里的特殊标记, 这些标…

C语言:使用指针打印数组内容

题目&#xff1a; 写一个函数打印arr数组的内容&#xff0c;不使用数组下标&#xff0c;使用指针。 arr是一维数组。 思路一&#xff1a;用 for循环 进行循环打印&#xff08;未写自定义函数&#xff09; 总体思路&#xff1a; &#xff08;一&#xff09;. 定义一维数组arr&a…