Skip to main content

pytest-data-extractor example workflow PyPI version

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.7

Use case

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

pip install -e .

or pip install it from Pypi:

pip install pytest-data-extractor

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": [
            {
                "test_file_path": "_20220719_21_00_10_806534.csv",
                "file_type": "csv"
            }
        ],
        "expected_result": null,
        "actual_result": null,
        "test_operator": null,
        "test_func": "test_bar",
        "test_status": 1,
        "test_duration": 0.046707000000000054,
        "meta_data": null
    }
]

In version 0.1.7 there's no recording of the expected_result, actual_result and test_operator since the test result is a PASS. Additionally, all objects passed to the upload_manager fixture will be saved as an external file that will be associated by test_file_path param. 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 suite_output_dir():
    return "my_files.output"


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

@pytest.fixture
def suite_output_file_prefix():
    return "my_special_prefix"

Enumeration

By default there are 3 values for the test values in the data_containers.py file:

class TestStatus(Enum):
    Skip = -1
    Fail = 0
    Pass = 1

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

Release files for pytest-data-extractor 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-data-extractor 0.1.7
File Size Uploaded
pytest_data_extractor-0.1.7.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-data-extractor 0.1.7
File Interpreter ABI Platform
pytest_data_extractor-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / pytest_data_extractor-0.1.7.tar.gz

Download URL pytest_data_extractor-0.1.7.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e067a284d57b33da64be467ea46d9af2bab3303fb544baeca44c5e4b24de9348
BLAKE2b-256 checksum
How to use checksums
ca8d3bd1328a5f5679ce7fe93289b064c4347a23ea7aebab8f758b17097905d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / pytest_data_extractor-0.1.7-py3-none-any.whl

Download URL pytest_data_extractor-0.1.7-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f204287e5371133228043885515f11844b99b7c4fe814b09b02642ed917a20a7
BLAKE2b-256 checksum
How to use checksums
bffc15fd811b66a9d818d9ab925c7b81a6e1714ab548bc9cdfa5a9a16ac56b1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page