pytest devs的插件,用于查看断言重写如何重新编码ast

pytest-ast-back-to-python的Python项目详细描述


See Build Status on Travis CISee Build Status on AppVeyor

pytest开发人员查看断言重写如何重新编码ast的插件


功能

pytest重写测试的ast(抽象语法树),以显示assert语句中涉及的子表达式。这个插件将重写的ast转换回python源代码,并显示它。

安装

您可以通过pipPyPI

$ pip install pytest-ast-back-to-python

用法

py.test --show-ast-as-python

示例

做一个简单的测试,比如:

deftest_simple():a=1b=2asserta+b==3

将重写的ast查看为python,如下所示:

$ py.test --show-ast-as-python test_simple.py
========================================test session starts========================================
plugins: ast-back-to-python-0.1.0, cov-2.2.1
collected 1 items

test_simple.py .
======================================== Rewritten AST as Python========================================
import builtins as @py_builtins
import _pytest.assertion.rewrite as @pytest_ar

def test_simple():
    a=1b=2
    @py_assert0 =1
    @py_assert2 =2
    @py_assert4 = @py_assert0 + @py_assert2
    @py_assert6 =3
    @py_assert5 = @py_assert4 == @py_assert6
    if not @py_assert5:
        @py_format8 = @pytest_ar._call_reprcompare(('==',), (@py_assert5,), ('(%(py1)s + %(py3)s) == %(py7)s',), (@py_assert4, @py_assert6)) % {'py3': @pytest_ar._saferepr(@py_assert2), 'py1': @pytest_ar._saferepr(@py_assert0), 'py7': @pytest_ar._saferepr(@py_assert6)}
        @py_format10 =('' + 'assert %(py9)s') % {'py9': @py_format8}
        raise AssertionError(@pytest_ar._format_explanation(@py_format10))
    @py_assert0 = @py_assert2 = @py_assert4 = @py_assert5 = @py_assert6 = None

贡献

我们非常欢迎您的贡献。测试可以用tox运行,请确保 在提交请求之前,覆盖范围至少保持不变。

许可证

“pytest ast back to python”是根据BSD-3许可证的条款发布的免费开源软件

这个Pytest插件是用Cookiecutter@hackebrotCookiecutter-pytest-plugin模板生成的。

问题

如果您遇到任何问题,请file an issue连同详细说明。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java数据不显示在FXML表中   java如何使整个JTable不可编辑   Java中的swing JTree JTable组合   Windows下的java诊断NIO DatagramChannel读取问题   java Dockerfile运行可执行文件   java手动初始化字节数组以测试更改   java Selenium Webdriver | DragAndDrop功能|也不例外,但代码不起作用   java Hibernate使用多对多关系和左连接多次加载同一实体?   java正在努力开发带有接口和泛型集的API   mongodb mongo java条件和如果不为null   Java程序不显示使用arduino ethernet shield在网页上发送的数据   java将JSONObject转换为JSONArray错误   java Box布局可以接受包含元素的大小吗?