Pytest Web3 Data
A pytest plugin to fetch test data from IPFS HTTP gateways during pytest execution.
Table of Contents
Installation
pip install pytest-web3-data
Usage
Let's say we want to store our testing data at test/data/*.
Optionally, first add test/data/ to .gitignore.
Create example test data:
mkdir -p test/data/staging/
echo 'hello world!' > ./test/data/staging/hello.txt
Upload the data to the InterPlanetary File System (IPFS).
One option is to use web3.storage. Install Node/NPM, and install the w3 CLI:
npm install --location=global @web3-storage/w3
The set your upload token from https://web3.storage:
w3 token
# Paste in token from the web UI
Upload the testing data to IPFS:
w3 put ./test/data/staging --name pytest-web3-data-example --hidden --no-wrap
This outputs a reference to the Content Identifier (CID), e.g.:
# Packed 1 file (0.0MB)
# bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu
⁂ Stored 1 file
⁂ https://w3s.link/ipfs/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu
When we create a test, e.g.:
# content of test_usage.py
def test_usage(web3_data):
assert web3_data.exists()
assert (web3_data / 'hello.txt').read_text() == "hello world!\n"
We can reference our CID either with a flag:
pytest --web3-data-dir=test/data/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu
or in the pytest.ini file:
# content of pytest.ini
[pytest]
web3_data_dir = test/data/bafybeigvfmtttajzj5no3jt2xavkdncxy3xapw3rndvoxmao72vhwy4osu
To add new data, copy the current web3_data directory into a staging directory, e.g. test/data/staging, add new data, and use this staging directory path for --web3-data-dir. Upload to IPFS before committing to Git.
For a robust and performant experience, we recommend running a local IPFS daemon, e.g. with ipfs-deskop.
Enjoy! 😊
License
pytest-web3-data is distributed under the terms of the MIT license.
Release files for pytest-web3-data 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_web3_data-0.2.1.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_web3_data-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / pytest_web3_data-0.2.1.tar.gz
| Download URL | pytest_web3_data-0.2.1.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
856d7d07ff53c983bb7667622fd556e990faf4536f3019716fe58acb8a00af26
|
|
BLAKE2b-256 checksum How to use checksums |
e6a1031e9bd32d643163c2182ca6ed7138bd1e319485db504e9c425d3e9d8a9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / pytest_web3_data-0.2.1-py3-none-any.whl
| Download URL | pytest_web3_data-0.2.1-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
05b9bf0ef00f0f841f9cb4c5baab70239d9bde144f86521992f33150b6275eb9
|
|
BLAKE2b-256 checksum How to use checksums |
a4f60a0bc2f1107d48da35dba5e790c907296910a00887e3c4bfc4223658f477
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|