Skip to content

olaaustine/pytest_dataguard

Repository files navigation

pytest-dataguard

A pytest plugin for validating CSV data files as part of your test suite. It helps ensure your data files meet quality standards by checking for null values and enforcing uniqueness constraints on specified columns.

Features

  • Null value checks: Ensure your CSV files have no missing values.
  • Uniqueness checks: Verify that specified columns contain only unique values.
  • Easy integration: Run data validation as part of your regular pytest workflow.

Installation

Install via pip:

pip install pytest-dataguard

Or install from uv:

uv add pytest-dataguard .

Usage

Run pytest with the plugin and specify the options:

pytest --file path/to/data.csv [--not_null] [--unique column1 --unique column2]
  • --file: Path to the CSV file to validate (required).
  • --not_null: Check that there are no null values in the file (optional, enabled by default).
  • --unique: Specify one or more columns to check for uniqueness. Can be used multiple times.

Example

Suppose you have a CSV file data.csv and want to ensure there are no nulls and that the id column is unique:

pytest --file data.csv --unique id

To check multiple columns for uniqueness:

pytest --file data.csv --unique id --unique email

How it works

When you run pytest with the pytest-dataguard options, the plugin will:

  • Load the specified CSV file using Polars
  • Check for null values --not_null is set by default
  • Check that specified columns have unique values if --unique is used
  • Fail the test session if any validation fails

Requirements

Contributing

Contributions are welcome! Please open issues or submit pull requests.

License

MIT License

About

A tiny plugin for pytests to validating CSV data files

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages