TESTIX
Testix is a Mocking framework for Python, meant to be used with pytest.
Testix is special because it allows you to specify what your mock objects do, and it then enforces your specifications automatically. It also reduces (albeit not entirely) mock setup. Other frameworks usually have a flow like this:
- setup mock
- let code do something with mock
- assert mock used in correct way
Testix flow is a bit different
- setup mock objects (
sockin the following example) - specify exactly what should happen to them using a Scenario context
TOC
Documentation
Read the full docs at readthedocs
Small Example
Here's a small example:
# create your object under test, pass in some mock objects
# in production, Chatbot will receive and actual socket object
# here we want to test what it does with the socket it receives
# and we do not want it to actually communicate with anyone
# to both those ends, we pass a mock, or fake, object.
self.tested = chatbot.Chatbot(Fake('sock')) # Fake('sock') is a mock object named "sock"
# create a Scenario context
# inside, you specify exactly what the unit should do with the objects its handed
with Scenario() as s:
# we can refer here to s.sock, because there is a mock named `sock`
s.sock.recv(4096) >> 'request text' # unit must call sock.recv(4096).
# this call will return 'request text'
s.sock.send('response text')
# call your unit's code
self.tested.go()
# Scenario context ends, and verifies everything happened exactly as specified
# No more, no less
Note that you do not have to setup sock.recv or sock.send - once sock is
set up, it will generate other mock objects automatically as you go along with
it. Only "top level" mock objects need to be setup explicitly.
Continue reading for further examples.
Installation
With pip:
$ pip install testix
Python 3 and Legacy Python (Python 2)
Testix works with Python 3. It will not work with legacy python.
Credit Where it's due
Testix started as a re-implementation of ideas from the Voodoo-Mock unit-testing framework. Since then it has evolved some different traits though.
License
This software is available under the MIT License, see the LICENSE file.
Metadata
Release files for testix 12.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| testix-12.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / testix-12.1.0-py3-none-any.whl
| Download URL | testix-12.1.0-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7953d7c2ff69987f589a968f44dd6b5fe2920c81c45354df0ea9473a423f6039
|
|
BLAKE2b-256 checksum How to use checksums |
c9d64084b78c8511bb70e0da1ef6b52dce4fc63a64a583ae166bb7ed0e64d6fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Security for testix 12.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.