
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Pytest plugin that allows you to easily define data-driven fixtures based on external files.
Fingest is a powerful pytest plugin that enables data-driven testing by automatically creating fixtures from external data files. It supports JSON, CSV, and XML formats out of the box, with extensible support for custom data loaders.
Install from PyPI:
pip install fingest
Or with Poetry:
poetry add fingest
[pytest]
fingest_fixture_path = tests/data # Path to your data files
users.json
[
{"id": 1, "name": "Alice", "email": "alice@example.com"},
{"id": 2, "name": "Bob", "email": "bob@example.com"}
]
products.csv
id,name,price,category
1,Laptop,999.99,Electronics
2,Mouse,29.99,Electronics
config.xml
<?xml version="1.0"?>
<config>
<database>
<host>localhost</host>
<port>5432</port>
</database>
</config>
from fingest import data_fixture, JSONFixture, CSVFixture, XMLFixture
@data_fixture("users.json", description="Test user data")
class user_data(JSONFixture):
"""Fixture for user test data."""
pass
@data_fixture("products.csv", description="Product catalog")
class product_data(CSVFixture):
"""Fixture for product data."""
pass
@data_fixture("config.xml", description="App configuration")
class config_data(XMLFixture):
"""Fixture for configuration data."""
pass
def test_user_count(user_data):
assert len(user_data) == 2
assert user_data[0]["name"] == "Alice"
def test_product_filtering(product_data):
electronics = product_data.filter_rows(category="Electronics")
assert len(electronics) == 2
def test_database_config(config_data):
host = config_data.get_text("database/host")
assert host == "localhost"
Fingest provides specialized fixture classes for different data formats:
For JSON data with dictionary and list operations:
@data_fixture("api_response.json")
class api_data(JSONFixture):
pass
def test_json_operations(api_data):
# Access dictionary methods
assert "users" in api_data.keys()
user_count = api_data.get("user_count", 0)
# Direct indexing
first_user = api_data["users"][0]
assert first_user["active"] is True
For CSV data with row and column operations:
@data_fixture("sales_data.csv")
class sales_data(CSVFixture):
pass
def test_csv_operations(sales_data):
# Get all column names
columns = sales_data.columns
assert "product_name" in columns
# Get specific column values
prices = sales_data.get_column("price")
assert all(float(p) > 0 for p in prices)
# Filter rows
expensive_items = sales_data.filter_rows(price="999.99")
assert len(expensive_items) > 0
For XML data with XPath and element operations:
@data_fixture("settings.xml")
class settings_data(XMLFixture):
pass
def test_xml_operations(settings_data):
# Find single elements
timeout = settings_data.find("timeout")
assert timeout.text == "30"
# Find multiple elements
features = settings_data.findall("features/feature")
assert len(features) == 3
# XPath queries
enabled_features = settings_data.xpath("//feature[@enabled='true']")
assert len(enabled_features) == 2
# Get text with default
debug_mode = settings_data.get_text("debug", "false")
assert debug_mode in ["true", "false"]
You can also create function-based fixtures for custom data processing:
@data_fixture("raw_data.json", description="Processed user data")
def processed_users(data):
"""Transform raw user data."""
return [
{
"id": user["id"],
"display_name": f"{user['first_name']} {user['last_name']}",
"email": user["email"].lower()
}
for user in data["users"]
]
def test_processed_data(processed_users):
assert processed_users[0]["display_name"] == "John Doe"
assert "@" in processed_users[0]["email"]
Extend Fingest to support any file format:
from fingest import register_loader
import yaml
def yaml_loader(path):
with open(path, 'r') as f:
return yaml.safe_load(f)
# Register the loader globally
register_loader("yaml", yaml_loader)
# Or use it for specific fixtures
@data_fixture("config.yaml", loader=yaml_loader)
class yaml_config(BaseFixture):
pass
[pytest]
fingest_fixture_path = tests/fixtures
import os
from fingest import data_fixture
env = os.getenv("TEST_ENV", "dev")
@data_fixture(f"config_{env}.json", description=f"Config for {env}")
class environment_config(JSONFixture):
pass
@data_fixture(file_path, description="", loader=None)
Register a class or function as a data-driven fixture.
Parameters:
file_path
(str): Path to data file relative to fingest_fixture_path
description
(str, optional): Description for debugging and documentationloader
(callable, optional): Custom data loader functionBaseFixture
data
: Access to raw loaded data__len__()
: Get data length__bool__()
: Check if data exists and is non-emptyJSONFixture(BaseFixture)
keys()
, values()
, items()
: Dictionary methods (if data is dict)get(key, default=None)
: Safe key accesslength()
: Get data length__getitem__(key)
: Direct indexingCSVFixture(BaseFixture)
rows
: List of all rowscolumns
: List of column namesget_column(name)
: Get all values from a columnfilter_rows(**kwargs)
: Filter rows by column values__getitem__(index)
: Get row by indexXMLFixture(BaseFixture)
root
: Root XML elementfind(path)
: Find first element matching XPathfindall(path)
: Find all elements matching XPathxpath(path)
: Execute XPath queryget_text(path, default="")
: Get text content with defaultregister_loader(extension, loader_func)
Register a custom data loader for a file extension.
Parameters:
extension
(str): File extension without dot (e.g., "yaml")loader_func
(callable): Function that takes a Path and returns loaded dataRun the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=fingest
# Run specific test categories
pytest tests/test_types.py # Test fixture types
pytest tests/test_plugin.py # Test plugin functionality
pytest tests/test_fixtures.py # Test fixture integration
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
git clone https://github.com/0x68/fingest.git
cd fingest
poetry install
poetry run pytest
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by Tim Fiedler
FAQs
Pytest plugin that allows you to easily define data-driven fixtures based on external files.
We found that fingest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.