astest: assert based testing
The quick, easy way to write tests in Python.
Usage
Get the tool by installing it from pip:
pip install astest
The tool doesn't have to be installed in your project's environment, you can also install it in your global Python (since it has no dependencies).
Then give it a file containing "tests" (explained below):
astest test_file.py
You can also easily run it via pipx:
pipx run astest test_file.py
Test files
astest expects a file that does assert's at runtime.
So to write a test for your code, simply do asserts in your file:
from my_library import add
assert add(12, 13) == 25
assert add(33, 77) == 100 # This one is false
assert add(123, 123) == 246
Running this will look like this:
$ astest examples/simple.py
Test 1..................................................................PASSED
Test 2..................................................................FAILED
Failing test: assert add(33, 77) == 100
Test 3..................................................................PASSED
===================== 1 failed, 2 passed in 0.00 seconds =====================
Debugging
If a test fails and you wish to debug it, you can run astest with --debug:
$ astest examples/simple.py
Test 1..................................................................PASSED
Test 2..................................................................FAILED
Failing test: assert add(33, 77) == 100
Starting debug session:
>>> add(33, 77)
110
>>> # Oh okay.
>>> ^D
Test 3..................................................................PASSED
===================== 1 failed, 2 passed in 0.00 seconds =====================
Local Development / Testing
- Create and activate a virtual environment
- Run
pip install -r requirements-dev.txtto do an editable install - Run
pytestto run tests
Type Checking
Run mypy .
Create and upload a package to PyPI
Make sure to bump the version in setup.cfg.
Then run the following commands:
rm -rf build dist
python setup.py sdist bdist_wheel
Then upload it to PyPI using twine:
twine upload dist/*
Metadata
Release files for astest 0.1.0
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 |
|---|---|---|---|---|
| astest-0.1.0.tar.gz | 5.0 kB | Without provenance | Details for astest-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| astest-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for astest-0.1.0-py3-none-any.whl |
Total release size: 10.6 kB
Release files / astest-0.1.0.tar.gz
| Download URL | astest-0.1.0.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fab8edd13fcd02ac5ed713a3baf99bf8c1a3e59fa380905b5de3ba59312668b
|
|
BLAKE2b-256 checksum How to use checksums |
62816197bab38d055d4326da2ffc9a0e4094b68d16ded3341946de6710468df1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / astest-0.1.0-py3-none-any.whl
| Download URL | astest-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a70e631a2e924a3ea5c351465fe604ba08b9fcc2df02bdfb8def4ad30405f09f
|
|
BLAKE2b-256 checksum How to use checksums |
cbd83b3f7e93f7c9af67980668da66645f857564fbf69f18925269e6578b805b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for astest 0.1.0
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.