Skip to main content

No project description provided

Project description

Pytest Web3 Data

PyPI - Version PyPI - Python Version test


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.

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

pytest_web3_data-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

pytest_web3_data-0.2.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_web3_data-0.2.0.tar.gz.

File metadata

  • Download URL: pytest_web3_data-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for pytest_web3_data-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d9420b297794b9b3091ceb724ba2edf1c696eb0503b61c80e66473a9f863aac6
MD5 f5b3ab274577e911bf24e459944d6d0f
BLAKE2b-256 1938631db3f5780aa5345e2bec76e493f3a70c15744cfce68bb5e07568c46091

See more details on using hashes here.

File details

Details for the file pytest_web3_data-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_web3_data-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22fa754890b7274f125636d406b7ca30cd27bc53fe98c8e26e64de63cbf227ae
MD5 3aa2396ed79501f40783b651604c7007
BLAKE2b-256 edcc426e60516853d2105a9bd44e3dfcf817385750b2a0b486fe75ca6f3dc366

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page