26 lines
942 B
Markdown
26 lines
942 B
Markdown
# Usage Examples
|
|
|
|
## Build your own annotation
|
|
|
|
Using another CSV format? The same `data_casts` methods each time? There is only one name for a test ID column? You can
|
|
easily build your own annotation. Just create a method that contains your common stuff:
|
|
|
|
```python
|
|
from pytest_csv_params.decorator import csv_params
|
|
|
|
def my_csv_params(data_file: str, **kwargs):
|
|
kwargs.setdefault("base_dir", "/var/test-data")
|
|
kwargs.setdefault("id_col", "Test Case ID")
|
|
kwargs.setdefault("header_renames", {
|
|
"Order #": "order_number",
|
|
"Price Total": "total_price",
|
|
})
|
|
kwargs.setdefault("data_casts", {
|
|
"total_price": float,
|
|
})
|
|
return csv_params(data_file, **kwargs)
|
|
```
|
|
|
|
When you now write a test, you can decorate it with `@my_csv_params("test-file-1.csv")`. You can override any of your
|
|
default settings by just adding it as a keyword argument: `@my_csv_params("test-file-1.csv", id_col="Test ID")`.
|