pytest-csv-params 1.0.0__tar.gz → 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/LICENSE.txt +20 -20
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/PKG-INFO +11 -7
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/README.md +196 -196
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/_ptcsvp/__init__.py +0 -0
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/_ptcsvp/cmdline.py +30 -30
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/_ptcsvp/configure.py +28 -28
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/_ptcsvp/parametrize.py +151 -150
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/_ptcsvp/plugin.py +27 -27
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/_ptcsvp/varname.py +59 -59
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/_ptcsvp/version.py +41 -40
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/pyproject.toml +162 -159
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/pytest_csv_params/__init__.py +0 -0
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/pytest_csv_params/decorator.py +12 -11
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/pytest_csv_params/dialect.py +25 -24
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/pytest_csv_params/exception.py +30 -30
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/pytest_csv_params/plugin.py +31 -31
- {pytest-csv-params-1.0.0 → pytest_csv_params-1.2.0}/pytest_csv_params/types.py +66 -65
- pytest-csv-params-1.0.0/setup.py +0 -34
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
Copyright Juergen Edelbluth and other contributors, https://juergen.rocks/
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright Juergen Edelbluth and other contributors, https://juergen.rocks/
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pytest-csv-params
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: Pytest plugin for Test Case Parametrization with CSV files
|
|
5
5
|
Home-page: https://git.codebau.dev/pytest-plugins/pytest-csv-params
|
|
6
6
|
License: MIT
|
|
7
7
|
Keywords: py.test,pytest,csv,params,parametrize,pytest-plugin,ddt,data-driven
|
|
8
8
|
Author: Juergen Edelbluth
|
|
9
9
|
Author-email: csv_params@jued.de
|
|
10
|
-
Requires-Python: >=3.
|
|
10
|
+
Requires-Python: >=3.9,<4.0
|
|
11
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
12
|
Classifier: Environment :: Console
|
|
13
13
|
Classifier: Environment :: Plugins
|
|
@@ -18,13 +18,17 @@ Classifier: Operating System :: MacOS :: MacOS X
|
|
|
18
18
|
Classifier: Operating System :: Microsoft :: Windows
|
|
19
19
|
Classifier: Operating System :: POSIX
|
|
20
20
|
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
22
|
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
26
|
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
24
27
|
Classifier: Topic :: Software Development :: Quality Assurance
|
|
25
28
|
Classifier: Topic :: Software Development :: Testing
|
|
26
29
|
Classifier: Topic :: Utilities
|
|
27
|
-
Requires-Dist:
|
|
30
|
+
Requires-Dist: attrs (>=24.2.0,<25.0.0)
|
|
31
|
+
Requires-Dist: pytest (>=8.3.0,<9.0.0)
|
|
28
32
|
Project-URL: Changelog, https://docs.codebau.dev/pytest-plugins/pytest-csv-params/pages/changelog.html
|
|
29
33
|
Project-URL: Documentation, https://docs.codebau.dev/pytest-plugins/pytest-csv-params/
|
|
30
34
|
Project-URL: Issue Tracker, https://git.codebau.dev/pytest-plugins/pytest-csv-params/issues
|
|
@@ -47,8 +51,8 @@ A pytest plugin to parametrize data-driven tests by CSV files.
|
|
|
47
51
|
|
|
48
52
|
## Requirements
|
|
49
53
|
|
|
50
|
-
- Python 3.
|
|
51
|
-
- pytest >=
|
|
54
|
+
- Python 3.9, 3.10, 3.11, 3.12, 3.13
|
|
55
|
+
- pytest >= 8.3
|
|
52
56
|
|
|
53
57
|
There's no operating system dependent code in this plugin, so it should run anywhere where pytest runs.
|
|
54
58
|
|
|
@@ -63,7 +67,7 @@ pip install pytest-csv-params
|
|
|
63
67
|
... or poetry ...
|
|
64
68
|
|
|
65
69
|
```bash
|
|
66
|
-
poetry add --dev pytest-csv-params
|
|
70
|
+
poetry add --group dev pytest-csv-params
|
|
67
71
|
```
|
|
68
72
|
|
|
69
73
|
## Documentation / User Guide
|
|
@@ -1,196 +1,196 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
# pytest-csv-params
|
|
4
|
-
|
|
5
|
-
A pytest plugin to parametrize data-driven tests by CSV files.
|
|
6
|
-
|
|
7
|
-
[](https://git.codebau.dev/pytest-plugins/pytest-csv-params)
|
|
8
|
-
[](https://pypi.org/project/pytest-csv-params/)
|
|
9
|
-
[](https://pypi.org/project/pytest-csv-params/)
|
|
10
|
-
[](https://pypi.org/project/pytest-csv-params/)
|
|
11
|
-
[](https://pypi.org/project/pytest-csv-params/)
|
|
12
|
-
|
|
13
|
-
## Requirements
|
|
14
|
-
|
|
15
|
-
- Python 3.
|
|
16
|
-
- pytest >=
|
|
17
|
-
|
|
18
|
-
There's no operating system dependent code in this plugin, so it should run anywhere where pytest runs.
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
Simply install it with pip...
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
pip install pytest-csv-params
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
... or poetry ...
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
poetry add --dev pytest-csv-params
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Documentation / User Guide
|
|
35
|
-
|
|
36
|
-
**Detailed documentation can be found under
|
|
37
|
-
[docs.codebau.dev/pytest-plugins/pytest-csv-params/](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/)**
|
|
38
|
-
|
|
39
|
-
## Usage: Command Line Argument
|
|
40
|
-
|
|
41
|
-
| Argument | Required | Description | Example |
|
|
42
|
-
|-------------------------|---------------|----------------------------------------------------------------------|----------------------------------------------|
|
|
43
|
-
| `--csv-params-base-dir` | no (optional) | Define a base dir for all relative-path CSV data files (since 0.1.0) | `pytest --csv-params-base-dir /var/testdata` |
|
|
44
|
-
|
|
45
|
-
## Usage: Decorator
|
|
46
|
-
|
|
47
|
-
Simply decorate your test method with `@csv_params` (`pytest_csv_params.decorator.csv_params`) and the following parameters:
|
|
48
|
-
|
|
49
|
-
| Parameter | Type | Description | Example |
|
|
50
|
-
|------------------|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
|
|
51
|
-
| `data_file` | `str` | The CSV file to use, relative or absolute path | `"/var/testdata/test1.csv"` |
|
|
52
|
-
| `base_dir` | `str` (optional) | Directory to look up relative CSV files (see `data_file`); overrides the command line argument | `join(dirname(__file__), "assets")` |
|
|
53
|
-
| `id_col` | `str` (optional) | Column name of the CSV that contains test case IDs | `"ID#"` |
|
|
54
|
-
| `dialect` | `csv.Dialect` (optional) | CSV Dialect definition (see [Python CSV Documentation](https://docs.python.org/3/library/csv.html#dialects-and-formatting-parameters)) | `csv.excel_tab` |
|
|
55
|
-
| `data_casts` | `dict` (optional) | Cast Methods for the CSV Data (see "Data Casting" below) | `{ "a": int, "b": float }` |
|
|
56
|
-
| `header_renames` | `dict` (optional) | Replace headers from the CSV file, so that they can be used as parameters for the test function (since 0.3.0) | `{ "Annual Amount of Bananas": "banana_count", "Cherry export price": "cherry_export_price" }` |
|
|
57
|
-
|
|
58
|
-
## CSV Format
|
|
59
|
-
|
|
60
|
-
The default CSV format is:
|
|
61
|
-
|
|
62
|
-
- `\r\n` as line ending
|
|
63
|
-
- All non-numeric fields are surrounded by `"`
|
|
64
|
-
- If you need a `"` in the value, use `""` (double quote)
|
|
65
|
-
- Fields are separated by comma (`,`)
|
|
66
|
-
|
|
67
|
-
## Usage Example
|
|
68
|
-
|
|
69
|
-
This example uses the CSV example from above.
|
|
70
|
-
|
|
71
|
-
```python
|
|
72
|
-
from pytest_csv_params.decorator import csv_params
|
|
73
|
-
|
|
74
|
-
@csv_params(
|
|
75
|
-
data_file="/data/test-lib/cases/addition.csv",
|
|
76
|
-
id_col="ID#",
|
|
77
|
-
data_casts={
|
|
78
|
-
"part_a": int,
|
|
79
|
-
"part_b": int,
|
|
80
|
-
"expected_result": int,
|
|
81
|
-
},
|
|
82
|
-
)
|
|
83
|
-
def test_addition(part_a, part_b, expected_result):
|
|
84
|
-
assert part_a + part_b == expected_result
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Shorthand example (no ID col, only string values):
|
|
88
|
-
|
|
89
|
-
```python
|
|
90
|
-
from pytest_csv_params.decorator import csv_params
|
|
91
|
-
|
|
92
|
-
@csv_params("/data/test-lib/cases/texts.csv")
|
|
93
|
-
def test_texts(text_a, text_b, text_c):
|
|
94
|
-
assert f"{text_a}:{text_b}" == text_c
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### More complex example
|
|
98
|
-
|
|
99
|
-
This example features nearly all things the plugin has to offer. You find this example also in the test cases, see `tests/test_complex_example.py`.
|
|
100
|
-
|
|
101
|
-
The CSV file (`tests/assets/example.csv`):
|
|
102
|
-
|
|
103
|
-
```text
|
|
104
|
-
"Test ID","Bananas shipped","Single Banana Weight","Apples shipped","Single Apple Weight","Container Size"
|
|
105
|
-
"Order-7","1503","0.5","2545","0.25","1500"
|
|
106
|
-
"Order-15","101","0.55","1474","0.33","550"
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
The Test (`tests/test_complex_example.py`):
|
|
110
|
-
|
|
111
|
-
```python
|
|
112
|
-
from math import ceil
|
|
113
|
-
from os.path import join, dirname
|
|
114
|
-
|
|
115
|
-
from pytest_csv_params.decorator import csv_params
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
@csv_params(
|
|
119
|
-
data_file="example.csv",
|
|
120
|
-
base_dir=join(dirname(__file__), "assets"),
|
|
121
|
-
id_col="Test ID",
|
|
122
|
-
header_renames={
|
|
123
|
-
"Bananas shipped": "bananas_shipped",
|
|
124
|
-
"Single Banana Weight": "banana_weight",
|
|
125
|
-
"Apples shipped": "apples_shipped",
|
|
126
|
-
"Single Apple Weight": "apple_weight",
|
|
127
|
-
"Container Size": "container_size",
|
|
128
|
-
},
|
|
129
|
-
data_casts={
|
|
130
|
-
"bananas_shipped": int,
|
|
131
|
-
"banana_weight": float,
|
|
132
|
-
"apples_shipped": int,
|
|
133
|
-
"apple_weight": float,
|
|
134
|
-
"container_size": int,
|
|
135
|
-
},
|
|
136
|
-
)
|
|
137
|
-
def test_container_size_is_big_enough(
|
|
138
|
-
bananas_shipped: int, banana_weight: float, apples_shipped: int, apple_weight: float, container_size: int
|
|
139
|
-
) -> None:
|
|
140
|
-
"""
|
|
141
|
-
This is just an example test case for the documentation.
|
|
142
|
-
"""
|
|
143
|
-
|
|
144
|
-
gross_weight = (banana_weight * bananas_shipped) + (apple_weight * apples_shipped)
|
|
145
|
-
assert ceil(gross_weight) <= container_size
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
If you decide not to rename the columns, the test would look like this:
|
|
149
|
-
|
|
150
|
-
```python
|
|
151
|
-
@csv_params(
|
|
152
|
-
data_file="example.csv",
|
|
153
|
-
base_dir=join(dirname(__file__), "assets"),
|
|
154
|
-
id_col="Test ID",
|
|
155
|
-
data_casts={
|
|
156
|
-
"Bananas_Shipped": int,
|
|
157
|
-
"Single_Banana_Weight": float,
|
|
158
|
-
"Apples_Shipped": int,
|
|
159
|
-
"Single_Apple_Weight": float,
|
|
160
|
-
"Container_Size": int,
|
|
161
|
-
},
|
|
162
|
-
)
|
|
163
|
-
def test_container_size_is_big_enough(
|
|
164
|
-
Bananas_Shipped: int, Single_Banana_Weight: float, Apples_Shipped: int, Single_Apple_Weight: float, Container_Size: int
|
|
165
|
-
) -> None:
|
|
166
|
-
...
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
## Changelog
|
|
170
|
-
|
|
171
|
-
- A detailed changelog is here:
|
|
172
|
-
[docs.codebau.dev/pytest-plugins/pytest-csv-params/pages/changelog.html](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/pages/changelog.html)
|
|
173
|
-
|
|
174
|
-
## Bugs etc.
|
|
175
|
-
|
|
176
|
-
Please send your issues to `csv-params_issues` (at) `jued.de`. Please include the following:
|
|
177
|
-
|
|
178
|
-
- Plugin Version used
|
|
179
|
-
- Pytest version
|
|
180
|
-
- Python version with operating system
|
|
181
|
-
|
|
182
|
-
It would be great if you could include example code that clarifies your issue.
|
|
183
|
-
|
|
184
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
185
|
-
|
|
186
|
-
## Pull Requests
|
|
187
|
-
|
|
188
|
-
Pull requests are always welcome. Since this Gitea instance is not open to public, just send an e-mail to discuss options.
|
|
189
|
-
|
|
190
|
-
Any changes that are made are to be backed by tests. Please give me a sign if you're going to break the existing API and let us discuss ways to handle that.
|
|
191
|
-
|
|
192
|
-
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
193
|
-
|
|
194
|
-
## Where are the sources?
|
|
195
|
-
|
|
196
|
-
The source code is available under [git.codebau.dev/pytest-plugins/pytest-csv-params](https://git.codebau.dev/pytest-plugins/pytest-csv-params).
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# pytest-csv-params
|
|
4
|
+
|
|
5
|
+
A pytest plugin to parametrize data-driven tests by CSV files.
|
|
6
|
+
|
|
7
|
+
[](https://git.codebau.dev/pytest-plugins/pytest-csv-params)
|
|
8
|
+
[](https://pypi.org/project/pytest-csv-params/)
|
|
9
|
+
[](https://pypi.org/project/pytest-csv-params/)
|
|
10
|
+
[](https://pypi.org/project/pytest-csv-params/)
|
|
11
|
+
[](https://pypi.org/project/pytest-csv-params/)
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Python 3.9, 3.10, 3.11, 3.12, 3.13
|
|
16
|
+
- pytest >= 8.3
|
|
17
|
+
|
|
18
|
+
There's no operating system dependent code in this plugin, so it should run anywhere where pytest runs.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Simply install it with pip...
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install pytest-csv-params
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
... or poetry ...
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
poetry add --group dev pytest-csv-params
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation / User Guide
|
|
35
|
+
|
|
36
|
+
**Detailed documentation can be found under
|
|
37
|
+
[docs.codebau.dev/pytest-plugins/pytest-csv-params/](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/)**
|
|
38
|
+
|
|
39
|
+
## Usage: Command Line Argument
|
|
40
|
+
|
|
41
|
+
| Argument | Required | Description | Example |
|
|
42
|
+
|-------------------------|---------------|----------------------------------------------------------------------|----------------------------------------------|
|
|
43
|
+
| `--csv-params-base-dir` | no (optional) | Define a base dir for all relative-path CSV data files (since 0.1.0) | `pytest --csv-params-base-dir /var/testdata` |
|
|
44
|
+
|
|
45
|
+
## Usage: Decorator
|
|
46
|
+
|
|
47
|
+
Simply decorate your test method with `@csv_params` (`pytest_csv_params.decorator.csv_params`) and the following parameters:
|
|
48
|
+
|
|
49
|
+
| Parameter | Type | Description | Example |
|
|
50
|
+
|------------------|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
|
|
51
|
+
| `data_file` | `str` | The CSV file to use, relative or absolute path | `"/var/testdata/test1.csv"` |
|
|
52
|
+
| `base_dir` | `str` (optional) | Directory to look up relative CSV files (see `data_file`); overrides the command line argument | `join(dirname(__file__), "assets")` |
|
|
53
|
+
| `id_col` | `str` (optional) | Column name of the CSV that contains test case IDs | `"ID#"` |
|
|
54
|
+
| `dialect` | `csv.Dialect` (optional) | CSV Dialect definition (see [Python CSV Documentation](https://docs.python.org/3/library/csv.html#dialects-and-formatting-parameters)) | `csv.excel_tab` |
|
|
55
|
+
| `data_casts` | `dict` (optional) | Cast Methods for the CSV Data (see "Data Casting" below) | `{ "a": int, "b": float }` |
|
|
56
|
+
| `header_renames` | `dict` (optional) | Replace headers from the CSV file, so that they can be used as parameters for the test function (since 0.3.0) | `{ "Annual Amount of Bananas": "banana_count", "Cherry export price": "cherry_export_price" }` |
|
|
57
|
+
|
|
58
|
+
## CSV Format
|
|
59
|
+
|
|
60
|
+
The default CSV format is:
|
|
61
|
+
|
|
62
|
+
- `\r\n` as line ending
|
|
63
|
+
- All non-numeric fields are surrounded by `"`
|
|
64
|
+
- If you need a `"` in the value, use `""` (double quote)
|
|
65
|
+
- Fields are separated by comma (`,`)
|
|
66
|
+
|
|
67
|
+
## Usage Example
|
|
68
|
+
|
|
69
|
+
This example uses the CSV example from above.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from pytest_csv_params.decorator import csv_params
|
|
73
|
+
|
|
74
|
+
@csv_params(
|
|
75
|
+
data_file="/data/test-lib/cases/addition.csv",
|
|
76
|
+
id_col="ID#",
|
|
77
|
+
data_casts={
|
|
78
|
+
"part_a": int,
|
|
79
|
+
"part_b": int,
|
|
80
|
+
"expected_result": int,
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
def test_addition(part_a, part_b, expected_result):
|
|
84
|
+
assert part_a + part_b == expected_result
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Shorthand example (no ID col, only string values):
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from pytest_csv_params.decorator import csv_params
|
|
91
|
+
|
|
92
|
+
@csv_params("/data/test-lib/cases/texts.csv")
|
|
93
|
+
def test_texts(text_a, text_b, text_c):
|
|
94
|
+
assert f"{text_a}:{text_b}" == text_c
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### More complex example
|
|
98
|
+
|
|
99
|
+
This example features nearly all things the plugin has to offer. You find this example also in the test cases, see `tests/test_complex_example.py`.
|
|
100
|
+
|
|
101
|
+
The CSV file (`tests/assets/example.csv`):
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
"Test ID","Bananas shipped","Single Banana Weight","Apples shipped","Single Apple Weight","Container Size"
|
|
105
|
+
"Order-7","1503","0.5","2545","0.25","1500"
|
|
106
|
+
"Order-15","101","0.55","1474","0.33","550"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The Test (`tests/test_complex_example.py`):
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from math import ceil
|
|
113
|
+
from os.path import join, dirname
|
|
114
|
+
|
|
115
|
+
from pytest_csv_params.decorator import csv_params
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@csv_params(
|
|
119
|
+
data_file="example.csv",
|
|
120
|
+
base_dir=join(dirname(__file__), "assets"),
|
|
121
|
+
id_col="Test ID",
|
|
122
|
+
header_renames={
|
|
123
|
+
"Bananas shipped": "bananas_shipped",
|
|
124
|
+
"Single Banana Weight": "banana_weight",
|
|
125
|
+
"Apples shipped": "apples_shipped",
|
|
126
|
+
"Single Apple Weight": "apple_weight",
|
|
127
|
+
"Container Size": "container_size",
|
|
128
|
+
},
|
|
129
|
+
data_casts={
|
|
130
|
+
"bananas_shipped": int,
|
|
131
|
+
"banana_weight": float,
|
|
132
|
+
"apples_shipped": int,
|
|
133
|
+
"apple_weight": float,
|
|
134
|
+
"container_size": int,
|
|
135
|
+
},
|
|
136
|
+
)
|
|
137
|
+
def test_container_size_is_big_enough(
|
|
138
|
+
bananas_shipped: int, banana_weight: float, apples_shipped: int, apple_weight: float, container_size: int
|
|
139
|
+
) -> None:
|
|
140
|
+
"""
|
|
141
|
+
This is just an example test case for the documentation.
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
gross_weight = (banana_weight * bananas_shipped) + (apple_weight * apples_shipped)
|
|
145
|
+
assert ceil(gross_weight) <= container_size
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
If you decide not to rename the columns, the test would look like this:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
@csv_params(
|
|
152
|
+
data_file="example.csv",
|
|
153
|
+
base_dir=join(dirname(__file__), "assets"),
|
|
154
|
+
id_col="Test ID",
|
|
155
|
+
data_casts={
|
|
156
|
+
"Bananas_Shipped": int,
|
|
157
|
+
"Single_Banana_Weight": float,
|
|
158
|
+
"Apples_Shipped": int,
|
|
159
|
+
"Single_Apple_Weight": float,
|
|
160
|
+
"Container_Size": int,
|
|
161
|
+
},
|
|
162
|
+
)
|
|
163
|
+
def test_container_size_is_big_enough(
|
|
164
|
+
Bananas_Shipped: int, Single_Banana_Weight: float, Apples_Shipped: int, Single_Apple_Weight: float, Container_Size: int
|
|
165
|
+
) -> None:
|
|
166
|
+
...
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Changelog
|
|
170
|
+
|
|
171
|
+
- A detailed changelog is here:
|
|
172
|
+
[docs.codebau.dev/pytest-plugins/pytest-csv-params/pages/changelog.html](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/pages/changelog.html)
|
|
173
|
+
|
|
174
|
+
## Bugs etc.
|
|
175
|
+
|
|
176
|
+
Please send your issues to `csv-params_issues` (at) `jued.de`. Please include the following:
|
|
177
|
+
|
|
178
|
+
- Plugin Version used
|
|
179
|
+
- Pytest version
|
|
180
|
+
- Python version with operating system
|
|
181
|
+
|
|
182
|
+
It would be great if you could include example code that clarifies your issue.
|
|
183
|
+
|
|
184
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
185
|
+
|
|
186
|
+
## Pull Requests
|
|
187
|
+
|
|
188
|
+
Pull requests are always welcome. Since this Gitea instance is not open to public, just send an e-mail to discuss options.
|
|
189
|
+
|
|
190
|
+
Any changes that are made are to be backed by tests. Please give me a sign if you're going to break the existing API and let us discuss ways to handle that.
|
|
191
|
+
|
|
192
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
193
|
+
|
|
194
|
+
## Where are the sources?
|
|
195
|
+
|
|
196
|
+
The source code is available under [git.codebau.dev/pytest-plugins/pytest-csv-params](https://git.codebau.dev/pytest-plugins/pytest-csv-params).
|
|
File without changes
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"""
|
|
2
|
-
This pytest plugin requires command line arguments that are parsed from the pytest framework. This module contains code
|
|
3
|
-
to instruct pytest to deliver the required values.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from _pytest.config.argparsing import Parser
|
|
7
|
-
|
|
8
|
-
HELP_TEXT = "set base dir for getting CSV data files from"
|
|
9
|
-
"""
|
|
10
|
-
This is the help text for the command line arguments that is added by :meth:`pytest_addoption`.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def pytest_addoption(parser: Parser, plugin_name: str = "csv-params") -> None:
|
|
15
|
-
"""
|
|
16
|
-
Entrypoint for pytest to extend the own :class:`Parser` with the things we need extra.
|
|
17
|
-
|
|
18
|
-
:param parser: The pytest command line argument parser
|
|
19
|
-
:param plugin_name: The name of our plugin, with default value
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
group = parser.getgroup(plugin_name)
|
|
23
|
-
group.addoption(
|
|
24
|
-
f"--{plugin_name}-base-dir",
|
|
25
|
-
action="store",
|
|
26
|
-
type=str,
|
|
27
|
-
default=None,
|
|
28
|
-
required=False,
|
|
29
|
-
help=HELP_TEXT,
|
|
30
|
-
)
|
|
1
|
+
"""
|
|
2
|
+
This pytest plugin requires command line arguments that are parsed from the pytest framework. This module contains code
|
|
3
|
+
to instruct pytest to deliver the required values.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from _pytest.config.argparsing import Parser
|
|
7
|
+
|
|
8
|
+
HELP_TEXT = "set base dir for getting CSV data files from"
|
|
9
|
+
"""
|
|
10
|
+
This is the help text for the command line arguments that is added by :meth:`pytest_addoption`.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def pytest_addoption(parser: Parser, plugin_name: str = "csv-params") -> None:
|
|
15
|
+
"""
|
|
16
|
+
Entrypoint for pytest to extend the own :class:`Parser` with the things we need extra.
|
|
17
|
+
|
|
18
|
+
:param parser: The pytest command line argument parser
|
|
19
|
+
:param plugin_name: The name of our plugin, with default value
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
group = parser.getgroup(plugin_name)
|
|
23
|
+
group.addoption(
|
|
24
|
+
f"--{plugin_name}-base-dir",
|
|
25
|
+
action="store",
|
|
26
|
+
type=str,
|
|
27
|
+
default=None,
|
|
28
|
+
required=False,
|
|
29
|
+
help=HELP_TEXT,
|
|
30
|
+
)
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"""
|
|
2
|
-
The pytest plugin needs a setup (:meth:`pytest_configure`) and a teardown (:meth:`pytest_unconfigure`) method
|
|
3
|
-
registered. This module contains the required methods for that.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from _pytest.config import Config
|
|
7
|
-
|
|
8
|
-
from _ptcsvp.plugin import Plugin
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def pytest_configure(config: Config, plugin_name: str = "csv_params") -> None:
|
|
12
|
-
"""
|
|
13
|
-
Register our Plugin
|
|
14
|
-
|
|
15
|
-
:param config: Pytets configuration class
|
|
16
|
-
:param plugin_name: The name of the pytest plugin, with default value
|
|
17
|
-
"""
|
|
18
|
-
config.pluginmanager.register(Plugin(config), f"{plugin_name}_plugin")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def pytest_unconfigure(config: Config, plugin_name: str = "csv_params") -> None:
|
|
22
|
-
"""
|
|
23
|
-
Remove our Plugin
|
|
24
|
-
|
|
25
|
-
:param config: Pytest configuration class
|
|
26
|
-
:param plugin_name: The name of the pytest plgin, with default value
|
|
27
|
-
"""
|
|
28
|
-
config.pluginmanager.unregister(f"{plugin_name}_plugin")
|
|
1
|
+
"""
|
|
2
|
+
The pytest plugin needs a setup (:meth:`pytest_configure`) and a teardown (:meth:`pytest_unconfigure`) method
|
|
3
|
+
registered. This module contains the required methods for that.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from _pytest.config import Config
|
|
7
|
+
|
|
8
|
+
from _ptcsvp.plugin import Plugin
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def pytest_configure(config: Config, plugin_name: str = "csv_params") -> None:
|
|
12
|
+
"""
|
|
13
|
+
Register our Plugin
|
|
14
|
+
|
|
15
|
+
:param config: Pytets configuration class
|
|
16
|
+
:param plugin_name: The name of the pytest plugin, with default value
|
|
17
|
+
"""
|
|
18
|
+
config.pluginmanager.register(Plugin(config), name=f"{plugin_name}_plugin")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def pytest_unconfigure(config: Config, plugin_name: str = "csv_params") -> None:
|
|
22
|
+
"""
|
|
23
|
+
Remove our Plugin
|
|
24
|
+
|
|
25
|
+
:param config: Pytest configuration class
|
|
26
|
+
:param plugin_name: The name of the pytest plgin, with default value
|
|
27
|
+
"""
|
|
28
|
+
config.pluginmanager.unregister(name=f"{plugin_name}_plugin")
|