
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
pytest-ast-back-to-python
Advanced tools
A plugin for pytest devs to view how assertion rewriting recodes the AST
.. image:: https://travis-ci.org/tomviner/pytest-ast-back-to-python.svg?branch=master :target: https://travis-ci.org/tomviner/pytest-ast-back-to-python :alt: See Build Status on Travis CI
.. image:: https://ci.appveyor.com/api/projects/status/github/tomviner/pytest-ast-back-to-python?branch=master :target: https://ci.appveyor.com/project/tomviner/pytest-ast-back-to-python/branch/master :alt: See Build Status on AppVeyor
A plugin for pytest devs to view how assertion rewriting recodes the AST
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.
You can install "pytest-ast-back-to-python" via pip_ from PyPI_::
$ pip install pytest-ast-back-to-python
.. code-block:: bash
py.test --show-ast-as-python
Take a trivial test like:
.. code-block:: python
def test_simple():
a = 1
b = 2
assert a + b == 3
View the rewritten AST as Python like this:
.. code-block:: bash
$ 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
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.
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.
If you encounter any problems, please file an issue_ along with a detailed description.
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _@hackebrot: https://github.com/hackebrot
.. _MIT: http://opensource.org/licenses/MIT
.. _BSD-3: http://opensource.org/licenses/BSD-3-Clause
.. _GNU GPL v3.0: http://www.gnu.org/licenses/gpl-3.0.txt
.. _Apache Software License 2.0: http://www.apache.org/licenses/LICENSE-2.0
.. _cookiecutter-pytest-plugin: https://github.com/pytest-dev/cookiecutter-pytest-plugin
.. _file an issue: https://github.com/tomviner/pytest-ast-back-to-python/issues
.. _pytest: https://github.com/pytest-dev/pytest
.. _tox: https://tox.readthedocs.org/en/latest/
.. _pip: https://pypi.python.org/pypi/pip/
.. _PyPI: https://pypi.python.org/pypi
FAQs
A plugin for pytest devs to view how assertion rewriting recodes the AST
We found that pytest-ast-back-to-python demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.