Skip to content

Commit cf4dc76

Browse files
authored
Update readme (#37)
* Fix typo * Update README * Fix mypy error
1 parent e7ae16b commit cf4dc76

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ Given you have the following project structure:
6969
│ ├── image.jpg
7070
│ └── image.png
7171
├── tests1/
72-
│ ├── data/
73-
│ │ ├── data1.txt
74-
│ │ └── data2.txt
75-
│ └── test_something_else.py
76-
└── test_something.py
72+
│ └── test_something.py
73+
└── tests2/
74+
├── data/
75+
│ ├── data1.txt
76+
│ └── data2.txt
77+
└── test_something_else.py
7778
```
7879

7980
### 1. Load file data — `@load`
@@ -103,22 +104,22 @@ def test_something2(file_path, data):
103104
```
104105

105106
```shell
106-
$ pytest test_something.py -v
107+
$ pytest tests1/test_something.py -v
107108
================================ test session starts =================================
108109
<snip>
109110
collected 2 items
110111

111-
tests/test_something.py::test_something1[data1.json] PASSED [ 50%]
112-
tests/test_something.py::test_something2[data2.txt] PASSED [100%]
112+
tests1/test_something.py::test_something1[data1.json] PASSED [ 50%]
113+
tests1/test_something.py::test_something2[data2.txt] PASSED [100%]
113114

114115
================================= 2 passed in 0.01s ==================================
115116
```
116117

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

@@ -150,16 +151,16 @@ def test_something2(file_path, data):
150151
```
151152

152153
```shell
153-
$ pytest test_something.py -v
154+
$ pytest tests1/test_something.py -v
154155
================================ test session starts =================================
155156
<snip>
156157
collected 5 items
157158

158-
tests/test_something.py::test_something1[data1.json:part1] PASSED [ 20%]
159-
tests/test_something.py::test_something1[data1.json:part2] PASSED [ 40%]
160-
tests/test_something.py::test_something2[data2.txt:part1] PASSED [ 60%]
161-
tests/test_something.py::test_something2[data2.txt:part2] PASSED [ 80%]
162-
tests/test_something.py::test_something2[data2.txt:part3] PASSED [100%]
159+
tests1/test_something.py::test_something1[data1.json:part1] PASSED [ 20%]
160+
tests1/test_something.py::test_something1[data1.json:part2] PASSED [ 40%]
161+
tests1/test_something.py::test_something2[data2.txt:part1] PASSED [ 60%]
162+
tests1/test_something.py::test_something2[data2.txt:part2] PASSED [ 80%]
163+
tests1/test_something.py::test_something2[data2.txt:part3] PASSED [100%]
163164

164165
================================= 5 passed in 0.01s ==================================
165166
```
@@ -196,14 +197,14 @@ def test_something(data):
196197
```
197198

198199
```shell
199-
$ pytest test_something.py -v
200+
$ pytest tests1/test_something.py -v
200201
================================ test session starts =================================
201202
<snip>
202203
collected 3 items
203204

204-
tests/test_something.py::test_something[image.gif] PASSED [ 33%]
205-
tests/test_something.py::test_something[image.jpg] PASSED [ 66%]
206-
tests/test_something.py::test_something[image.png] PASSED [100%]
205+
tests1/test_something.py::test_something[image.gif] PASSED [ 33%]
206+
tests1/test_something.py::test_something[image.jpg] PASSED [ 66%]
207+
tests1/test_something.py::test_something[image.png] PASSED [100%]
207208

208209
================================= 3 passed in 0.01s ==================================
209210
```

src/pytest_data_loader/loaders/impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def parametrizer_func(self) -> Callable[..., Iterable[Any]]:
194194

195195
@wraps(f)
196196
def _parametrizer_func(*args: Any, **kwargs: Any) -> Iterable[Any]:
197-
parametrized_data = f(*args, **kwargs)
197+
parametrized_data: Any = f(*args, **kwargs)
198198
if not isinstance(parametrized_data, Iterable) or isinstance(parametrized_data, str | bytes):
199199
t = parametrized_data if isinstance(parametrized_data, type) else type(parametrized_data)
200200
raise ValueError(f"Parametrized data must be an iterable container, not {t.__name__!r}")

src/pytest_data_loader/loaders/loaders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def parametrize(
153153
- object: each key-value pair as a tuple
154154
- scalar: the whole value as a single parameter
155155
- Any other files with text data (.txt, .csv, .log, etc.): each line
156-
- Binary files: Not supported without a cusom logic. An error will be raised.
156+
- Binary files: Not supported without a custom logic. An error will be raised.
157157
:param filter_func: A function to filter the split data parts. Only matching parts are included as the test
158158
parameters.
159159
:param process_func: A function to adjust the shape of each split data before passing it to the test function.

0 commit comments

Comments
 (0)