pytest-ast-back-to-python
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_assert2 = a + b
@py_assert4 = 3
@py_assert3 = @py_assert2 == @py_assert4
if @py_assert3 is None:
from _pytest.warning_types import PytestAssertRewriteWarning
from warnings import warn_explicit
warn_explicit(PytestAssertRewriteWarning('asserting the value None, please use "assert is None"'), category=None, filename='/home/tom/.virtualenvs/tmp-483cf04ecc31dda8/test_thing.py', lineno=4)
if not @py_assert3:
@py_format6 = @pytest_ar._call_reprcompare(('==',), (@py_assert3,), ('(%(py0)s + %(py1)s) == %(py5)s',), (@py_assert2, @py_assert4)) % {'py0': @pytest_ar._saferepr(a) if 'a' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(a) else 'a', 'py1': @pytest_ar._saferepr(b) if 'b' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(b) else 'b', 'py5': @pytest_ar._saferepr(@py_assert4)}
@py_format8 = ('' + 'assert %(py7)s') % {'py7': @py_format6}
raise AssertionError(@pytest_ar._format_explanation(@py_format8))
@py_assert2 = @py_assert3 = @py_assert4 = 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.
Metadata
Release files for pytest-ast-back-to-python 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-ast-back-to-python-1.2.1.tar.gz | 15.8 kB | Without provenance | Details for pytest-ast-back-to-python-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_ast_back_to_python-1.2.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pytest_ast_back_to_python-1.2.1-py2.py3-none-any.whl |
Total release size: 29.2 kB
Release files / pytest-ast-back-to-python-1.2.1.tar.gz
| Download URL | pytest-ast-back-to-python-1.2.1.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e594728637d0d03f639b91dc6afdb03f90dd8ccf783ec714545f18d0e9232dc
|
|
BLAKE2b-256 checksum How to use checksums |
2bfe5788791ddfdcdebf1ecb4d1b0e95c00009b4bd75cd5218f0df9f5d6fb2e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Release files / pytest_ast_back_to_python-1.2.1-py2.py3-none-any.whl
| Download URL | pytest_ast_back_to_python-1.2.1-py2.py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1a019c3f3a646572f63b53069ce24efed678b8abdacf67259ae7118ca09e78a9
|
|
BLAKE2b-256 checksum How to use checksums |
10f1a74fb82f95cd4603179f4db79bdcdd00bd4cfe88bba344ececa750599dab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for pytest-ast-back-to-python 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.