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.
- 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.
Install via pip:
pip install pytest-dataguardOr install from uv:
uv add pytest-dataguard .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.
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 idTo check multiple columns for uniqueness:
pytest --file data.csv --unique id --unique emailWhen you run pytest with the pytest-dataguard options, the plugin will:
- Load the specified CSV file using Polars
- Check for null values
--not_nullis set by default - Check that specified columns have unique values if
--uniqueis used - Fail the test session if any validation fails
Contributions are welcome! Please open issues or submit pull requests.