Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ Given you have the following project structure:
│ ├── image.jpg
│ └── image.png
├── tests1/
│ ├── data/
│ │ ├── data1.txt
│ │ └── data2.txt
│ └── test_something_else.py
└── test_something.py
│ └── test_something.py
└── tests2/
├── data/
│ ├── data1.txt
│ └── data2.txt
└── test_something_else.py
```

### 1. Load file data — `@load`
Expand Down Expand Up @@ -103,22 +104,22 @@ def test_something2(file_path, data):
```

```shell
$ pytest test_something.py -v
$ pytest tests1/test_something.py -v
================================ test session starts =================================
<snip>
collected 2 items

tests/test_something.py::test_something1[data1.json] PASSED [ 50%]
tests/test_something.py::test_something2[data2.txt] PASSED [100%]
tests1/test_something.py::test_something1[data1.json] PASSED [ 50%]
tests1/test_something.py::test_something2[data2.txt] PASSED [100%]

================================= 2 passed in 0.01s ==================================
```

> [!NOTE]
> If both `./test_something.py` and `./tests1/test_something_else.py` happen to have the above same loader definitions,
> the first test function will load `./data/data1.json` for both test files, and the second test function will load
> `data2.txt` from each test file's **nearest** `data` directory. This ensures that each test file loads data from its
> nearest data directory.
> If both `./tests1/test_something.py` and `./tests2/test_something_else.py` happen to have the above same loader
> definitions, the first test function will load `./data/data1.json` for both test files, and the second test function
> will load `data2.txt` from each test file's **nearest** `data` directory. This ensures that each test file loads data
> from its nearest data directory.
> This behavior applies to all loaders.


Expand Down Expand Up @@ -150,16 +151,16 @@ def test_something2(file_path, data):
```

```shell
$ pytest test_something.py -v
$ pytest tests1/test_something.py -v
================================ test session starts =================================
<snip>
collected 5 items

tests/test_something.py::test_something1[data1.json:part1] PASSED [ 20%]
tests/test_something.py::test_something1[data1.json:part2] PASSED [ 40%]
tests/test_something.py::test_something2[data2.txt:part1] PASSED [ 60%]
tests/test_something.py::test_something2[data2.txt:part2] PASSED [ 80%]
tests/test_something.py::test_something2[data2.txt:part3] PASSED [100%]
tests1/test_something.py::test_something1[data1.json:part1] PASSED [ 20%]
tests1/test_something.py::test_something1[data1.json:part2] PASSED [ 40%]
tests1/test_something.py::test_something2[data2.txt:part1] PASSED [ 60%]
tests1/test_something.py::test_something2[data2.txt:part2] PASSED [ 80%]
tests1/test_something.py::test_something2[data2.txt:part3] PASSED [100%]

================================= 5 passed in 0.01s ==================================
```
Expand Down Expand Up @@ -196,14 +197,14 @@ def test_something(data):
```

```shell
$ pytest test_something.py -v
$ pytest tests1/test_something.py -v
================================ test session starts =================================
<snip>
collected 3 items

tests/test_something.py::test_something[image.gif] PASSED [ 33%]
tests/test_something.py::test_something[image.jpg] PASSED [ 66%]
tests/test_something.py::test_something[image.png] PASSED [100%]
tests1/test_something.py::test_something[image.gif] PASSED [ 33%]
tests1/test_something.py::test_something[image.jpg] PASSED [ 66%]
tests1/test_something.py::test_something[image.png] PASSED [100%]

================================= 3 passed in 0.01s ==================================
```
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_data_loader/loaders/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def parametrizer_func(self) -> Callable[..., Iterable[Any]]:

@wraps(f)
def _parametrizer_func(*args: Any, **kwargs: Any) -> Iterable[Any]:
parametrized_data = f(*args, **kwargs)
parametrized_data: Any = f(*args, **kwargs)
if not isinstance(parametrized_data, Iterable) or isinstance(parametrized_data, str | bytes):
t = parametrized_data if isinstance(parametrized_data, type) else type(parametrized_data)
raise ValueError(f"Parametrized data must be an iterable container, not {t.__name__!r}")
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_data_loader/loaders/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def parametrize(
- object: each key-value pair as a tuple
- scalar: the whole value as a single parameter
- Any other files with text data (.txt, .csv, .log, etc.): each line
- Binary files: Not supported without a cusom logic. An error will be raised.
- Binary files: Not supported without a custom logic. An error will be raised.
:param filter_func: A function to filter the split data parts. Only matching parts are included as the test
parameters.
:param process_func: A function to adjust the shape of each split data before passing it to the test function.
Expand Down