A plugin for pytest devs to view how assertion rewriting recodes the AST
Project description
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 a + b == 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
Built Distribution
File details
Details for the file pytest-ast-back-to-python-1.0.1.tar.gz
.
File metadata
- Download URL: pytest-ast-back-to-python-1.0.1.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c459b3ea9b0a41f2cdf6c80b7642db1ee40d74b98b58434749932190b82c2e4e |
|
MD5 | 9d900c1a5e5299dab897e3ac00a0a1b9 |
|
BLAKE2b-256 | 527c3d6f8121b9199258d0bb606f7648a403f697e4f8a5e907036675a52f404d |
File details
Details for the file pytest_ast_back_to_python-1.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_ast_back_to_python-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9913ff3d2f6e3cc3995b5af93dfced69ee3ee29ab06c6b35e548fc8642bc140f |
|
MD5 | 051a6eb38bae99220f9b755177f61893 |
|
BLAKE2b-256 | 82adaa69edf400b13bcfe8b815ca97ad349abfda561c066639b5a38f8cf3caff |