Skip to main content

A plugin for pytest devs to view how assertion rewriting recodes the AST

Project description

See Build Status on Travis CI See Build Status on AppVeyor

A plugin for pytest devs to view how assertion rewriting recodes the AST


Features

Pytest rewrites the AST (abstract syntax tree) of your tests, for the purpose of displaying the subexpressions involved in your assert statements. This plugin converts that rewritten AST back to Python source, and displays it.

Installation

You can install “pytest-ast-back-to-python” via pip from PyPI:

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

Usage

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

Example

Take a trivial test like:

def test_simple():
    a = 1
    b = 2
    assert 1 + 2 == 3

View the rewritten AST as Python like this:

$ 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 = 1
    b = 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

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the BSD-3 license, “pytest-ast-back-to-python” is free and open source software

This Pytest plugin was generated with Cookiecutter along with @hackebrot’s Cookiecutter-pytest-plugin template.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-ast-back-to-python-0.1.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

pytest_ast_back_to_python-0.1.0-py2.py3-none-any.whl (14.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-ast-back-to-python-0.1.0.tar.gz.

File metadata

File hashes

Hashes for pytest-ast-back-to-python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d1752cd17881027c95ddcf0c1f1af7ed17f5a9ac04f8333e096f912263ff3907
MD5 4d620d2d833b568e6ea1d923b3145b8c
BLAKE2b-256 96e084cff3bc54263670ff405a3546940cb049a9d12452d1e28539e2a8a9b012

See more details on using hashes here.

File details

Details for the file pytest_ast_back_to_python-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_ast_back_to_python-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 32088340ec5fb006366e80f5cb90b83111690b47b792eeb16b22c2df71b58558
MD5 e4c718a9b1791c9b5e1e4a5e69b7dadb
BLAKE2b-256 946895258b44011394f612ac0da423e1452246048b47eb800e8faed223596bdd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page