Introduction
pytest-dummynet provides a py.test fixture for working with dummy-networks in pytest on Linux machines. By dummy-networks we refer to setups with network namespaces, virtual ethernets, etc.
The DummyNet class is a python wrapper for the linux ‘ip netns’ and ‘ip link’ tools. The methods of the class parse args directly to the command-line in your linux OS.
So far, Ubuntu and Debian are supported, but please make sure, that you have the iproute2 linux-package installed with:
apt-get install iproute2
Other Linux operating systems have not been tested, but feel free to open an issue if support is needed.
Installation
To install pytest-dummynet:
pip install pytest-dummynet
Usage
To make it easy to use in with pytest the DummyNet object can be injected into a test function by using the dummynet fixture.
Example:
def test_run_fail(dummynet):
with dummynet.host() as shell:
demo0 = shell.netns_add(name="namespace1")
demo1 = shell.netns_add(name="namespace2")
shell.link_veth_add(p1_name="peer1", p2_name="peer2")
The dummynet argument is an instance of the DummyNet class.
For a complete example of a local network setup see the test in ‘test/test_dummynet.py’.
You can try playing around with the class methods in dummynet.py and call the commands in self.shell.run(cmd) from the command-line. This can give a better idea of the functionality.
Relase new version
Edit NEWS.rst and wscript (set correct VERSION)
Run
./waf upload
Source code
The main functionality is found in src/dummy_net.py and the corresponding unit test is in test/test_dummynet.py if you want to play/modify/fix the code this would, in most cases, be the place to start.
Developer Notes
We try to make our projects as independent as possible of a local system setup. For example with our native code (C/C++) we compile as much as possible from source, since this makes us independent of what is currently installed (libraries etc.) on a specific machine.
To “fetch” sources we use Waf (https://waf.io/) augmented with dependency resolution capabilities: https://github.com/steinwurf/waf
The goal is to enable a work-flow where running:
./waf configure ./waf build --run_tests
Configures, builds and runs any available tests for a given project, such that you as a developer can start hacking at the code.
For Python project this is a bit unconventional, but we think it works well.
Tests
The tests will run automatically by passing --run_tests to waf:
./waf --run_tests
This follows what seems to be “best practice” advise, namely to install the package in editable mode in a virtualenv.
Notes
Why use an src folder (https://hynek.me/articles/testing-packaging/). tl;dr you should run your tests in the same environment as your users would run your code. So by placing the source files in a non-importable folder you avoid accidentally having access to resources not added to the Python package your users will install…
Python packaging guide: https://packaging.python.org/distributing/
Metadata
Release files for pytest-dummynet 2.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 | Actions Reset |
|---|---|---|---|---|
| pytest_dummynet-2.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pytest_dummynet-2.1.0-py2.py3-none-any.whl |
Release files / pytest_dummynet-2.1.0-py2.py3-none-any.whl
| Download URL | pytest_dummynet-2.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1447a2029496ff99c0e3c3eec9da4077908b1aa3e6377e855cefd9a155680dad
|
|
BLAKE2b-256 checksum How to use checksums |
d84589d24b2a350cd39e43306435fb424c605bee3ca67b73b83c02e94fa9367c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Security for pytest-dummynet 2.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.