[](https://pypi.org/project/pytest-ast-transformer/)
## About
AST Transformer integrated with py.test.
Useful for debug, refactoring, 'clean asserts' (see [examples/replace_asserts](examples/replace_asserts))
Support options
---------------
| Options | Description |
| ----------- | ----------- |
| `--show-code` | show generated code |
| `--disable-transforms` | disable all ast transformers |
## Install
```bash
pip install pytest-ast-transformer
```
## Usage
* Write ast transformer
```python
# transformer.py
import ast
from pytest_ast_transformer.ast_transformer import PytestTransformer
def my_assert(test_result, msg=''):
print(f'my assert: {test_result} {msg}')
assert test_result, msg
class AssertTransformer(PytestTransformer):
context = {
'my_assert': my_assert
}
def visit_Assert(self, node: ast.Assert) -> ast.Expr:
func_name = ast.Name(id='my_assert', ctx=ast.Load())
call_func = ast.Call(func=func_name, args=[node.test, node.msg], keywords=[])
expr = ast.Expr(value=call_func)
return ast.fix_missing_locations(expr)
```
* Register new ast transformer
```python
# conftest.py
from pytest_ast_transformer.ast_manager import ASTManager
from tests.transformer import AssertTransformer
def pytest_register_ast_transformer(ast_manager: ASTManager):
ast_manager.add_transformer(AssertTransformer())
```
Metadata
Release files for pytest-ast-transformer 1.0.3
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-transformer-1.0.3.tar.gz | 6.3 kB | Without provenance | Details for pytest-ast-transformer-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_ast_transformer-1.0.3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for pytest_ast_transformer-1.0.3-py2.py3-none-any.whl |
Total release size: 17.8 kB
Release files / pytest-ast-transformer-1.0.3.tar.gz
| Download URL | pytest-ast-transformer-1.0.3.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
346f5d6a2500449099c68c3f35ea7965525d3d52012089ddda565babb99246a8
|
|
BLAKE2b-256 checksum How to use checksums |
8f4f72599150a0542d56027036f9ce3eb649ed899b4d080c9f9715762d537674
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3
|
Release files / pytest_ast_transformer-1.0.3-py2.py3-none-any.whl
| Download URL | pytest_ast_transformer-1.0.3-py2.py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
526d8a24b148f303ac2eae85308141fe85a13077afdc9ecbfeec7b74e91f4072
|
|
BLAKE2b-256 checksum How to use checksums |
0f6ce10d21f512016ed4b8795dcced850e3afedb83a6af0865f044601dd9ed0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3
|
Security for pytest-ast-transformer 1.0.3
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.