Skip to main content

A pytest plugin to extract relevant metadata about tests into an external file (currently only json support)

Project description

pytest-data-extractor example workflow

Pytest plugin intended for extracting test data and metadata and serializing it into a file. The plugin currently support json files.

This is a completely open source project so everyone are more than welcome to join and extended it.

Version 0.1.6

Use case

pip install the package to your project's virtual environment. Directly from plugin folder:

pip install -e .

Go to a test file and now simply add upload_manager fixture in order to save a variable (except callable), Like so:

# test_foo.py

def test_bar(upload_manager):
    expected_value = upload_manager(1000)
    assert expected_value == 1000, "assert failed"

Activate the plugin with the pytest cli with the command:

pytest --output_test_data True

Now the data passed to upload_manager, as well as the test data that is specified at the TestData container will be stored in an external file. For a json file output:

[
  {
    "test_input": 1000,
    "expected": 1000,
    "actual": 1000,
    "operator": "==",
    "test_func": "test_bar",
    "test_status": 1,
    "test_duration": 0.010749192908406258
  }
]

There are specific input types that instead of being serialized to the main json file, will be stored as cache files. Currently pandas dataframes are supported, so if upload_manager is invoked on it, it will be stored in cache folder.
There's no garbage collection so be mindful how and where the files are stored.

Miscellaneous

For order sakes, the plugin will use a test comparison convention of:

* left- actual result.
* right- expected result.

conftest.py hooks and fixtures

In order to change the folder for either cache or output files, use conftest.py with the correct fixtures. example:

# conftest.py
import pytest


@pytest.fixture
def session_output_dir():
    return "my_files.output"


@pytest.fixture
def session_temp_dir():
    return "my_files.temp"

The default directories will be at the root where the pytest is called.

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_data_extractor-0.1.6.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

pytest_data_extractor-0.1.6-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_data_extractor-0.1.6.tar.gz.

File metadata

  • Download URL: pytest_data_extractor-0.1.6.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytest_data_extractor-0.1.6.tar.gz
Algorithm Hash digest
SHA256 3be4b5a2df71fbca9378a6a495425604c01713327ae79b072c9886c9044d71ea
MD5 2394bbf91c3a42960e0a1b4971c3d839
BLAKE2b-256 bbc9ffc4454a6fb57521a8834b07fc124bfb351be8aecd0da43c8222eaac1b10

See more details on using hashes here.

File details

Details for the file pytest_data_extractor-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: pytest_data_extractor-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytest_data_extractor-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2ffc9a895f631e26b1e8e76846f95d013d5e972ed701d745de28724f239b96df
MD5 cd64b5fc90d953ac9f55ea386b507c24
BLAKE2b-256 84f33a344dca090ea5cce4cf3ba14398593e7b844e1417671cdbb14b3dca4198

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