No project description provided
Project description
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
Enjoy! 😊
License
pytest-web3-data
is distributed under the terms of the MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest_web3_data-0.1.2.tar.gz
.
File metadata
- Download URL: pytest_web3_data-0.1.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6341a80acf1d7fa4a2835810efacde2890228342a4f53260fd827ded5599edf2 |
|
MD5 | 80f01531f5782749ab9121835261a905 |
|
BLAKE2b-256 | 55ae2c98be3d497a131987897a64bd52896923b0873407fad8e121b08a3be44f |
File details
Details for the file pytest_web3_data-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: pytest_web3_data-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.23.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f26335316be6de8da40838687e52864980cda3ef67005ded9b157839bc358008 |
|
MD5 | afe953ac39e0891fb93ed0e8ac135d69 |
|
BLAKE2b-256 | 451d41b1608b4ec8512f78861e2e34a830b9441f2c49b4303eb47686e27eab68 |