pytest-csv-params 1.2.0__tar.gz → 1.3.2__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.
Files changed (19) hide show
  1. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/LICENSE.txt +20 -20
  2. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/PKG-INFO +49 -14
  3. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/README.md +197 -196
  4. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/_ptcsvp/__init__.py +0 -0
  5. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/_ptcsvp/cmdline.py +30 -30
  6. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/_ptcsvp/configure.py +28 -28
  7. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/_ptcsvp/parametrize.py +165 -151
  8. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/_ptcsvp/plugin.py +27 -27
  9. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/_ptcsvp/varname.py +59 -59
  10. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/_ptcsvp/version.py +41 -41
  11. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/pyproject.toml +169 -162
  12. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/pytest_csv_params/__init__.py +0 -0
  13. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/pytest_csv_params/decorator.py +12 -12
  14. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/pytest_csv_params/dialect.py +25 -25
  15. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/pytest_csv_params/exception.py +30 -30
  16. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/pytest_csv_params/plugin.py +31 -31
  17. pytest_csv_params-1.3.2/pytest_csv_params/shortcut.py +13 -0
  18. {pytest_csv_params-1.2.0 → pytest_csv_params-1.3.2}/pytest_csv_params/types.py +66 -66
  19. pytest_csv_params-1.3.2/pytest_csv_params/warning.py +20 -0
@@ -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,36 +1,70 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: pytest-csv-params
3
- Version: 1.2.0
3
+ Version: 1.3.2
4
4
  Summary: Pytest plugin for Test Case Parametrization with CSV files
5
- Home-page: https://git.codebau.dev/pytest-plugins/pytest-csv-params
6
- License: MIT
5
+ License: Copyright Juergen Edelbluth and other contributors, https://juergen.rocks/
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
25
  Keywords: py.test,pytest,csv,params,parametrize,pytest-plugin,ddt,data-driven
8
26
  Author: Juergen Edelbluth
9
27
  Author-email: csv_params@jued.de
10
- Requires-Python: >=3.9,<4.0
28
+ Requires-Python: >=3.9,<3.14
11
29
  Classifier: Development Status :: 5 - Production/Stable
12
- Classifier: Environment :: Console
13
30
  Classifier: Environment :: Plugins
31
+ Classifier: Environment :: Console
14
32
  Classifier: Framework :: Pytest
15
33
  Classifier: Intended Audience :: Developers
16
34
  Classifier: License :: OSI Approved :: MIT License
17
- Classifier: Operating System :: MacOS :: MacOS X
18
- Classifier: Operating System :: Microsoft :: Windows
19
- Classifier: Operating System :: POSIX
20
- Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.8
21
36
  Classifier: Programming Language :: Python :: 3.9
22
37
  Classifier: Programming Language :: Python :: 3.10
23
38
  Classifier: Programming Language :: Python :: 3.11
24
39
  Classifier: Programming Language :: Python :: 3.12
25
40
  Classifier: Programming Language :: Python :: 3.13
26
- Classifier: Programming Language :: Python :: 3.8
27
- Classifier: Topic :: Software Development :: Quality Assurance
28
41
  Classifier: Topic :: Software Development :: Testing
42
+ Classifier: Topic :: Software Development :: Quality Assurance
43
+ Classifier: Operating System :: POSIX
44
+ Classifier: Operating System :: Microsoft :: Windows
45
+ Classifier: Operating System :: MacOS :: MacOS X
29
46
  Classifier: Topic :: Utilities
30
- Requires-Dist: attrs (>=24.2.0,<25.0.0)
31
- Requires-Dist: pytest (>=8.3.0,<9.0.0)
47
+ Provides-Extra: dev
48
+ Requires-Dist: Sphinx (>=5.1.1,<6) ; extra == "dev"
49
+ Requires-Dist: attrs (>=24.2)
50
+ Requires-Dist: livereload (>=2.6.3) ; extra == "dev"
51
+ Requires-Dist: myst-parser (>=0.18.0) ; extra == "dev"
52
+ Requires-Dist: pytest (>=8.3,<9)
53
+ Requires-Dist: pytest-bandit (>=0.6.1) ; extra == "dev"
54
+ Requires-Dist: pytest-black (>=0.3.12) ; extra == "dev"
55
+ Requires-Dist: pytest-clarity (>=1.0.1) ; extra == "dev"
56
+ Requires-Dist: pytest-cov (>=4.1) ; extra == "dev"
57
+ Requires-Dist: pytest-isort (>=3.0) ; extra == "dev"
58
+ Requires-Dist: pytest-mock (>=3.8.2) ; extra == "dev"
59
+ Requires-Dist: pytest-order (>=1.0.1,<2) ; extra == "dev"
60
+ Requires-Dist: sphinx-autodoc-typehints (>=1.19.2,<2) ; extra == "dev"
61
+ Requires-Dist: sphinx-material (>=0.0.35) ; extra == "dev"
62
+ Requires-Dist: tomli (>=2.0.1) ; extra == "dev"
63
+ Requires-Dist: tox (>=3.25.1,<4) ; extra == "dev"
64
+ Requires-Dist: tox-poetry (>=0.4.1) ; extra == "dev"
32
65
  Project-URL: Changelog, https://docs.codebau.dev/pytest-plugins/pytest-csv-params/pages/changelog.html
33
66
  Project-URL: Documentation, https://docs.codebau.dev/pytest-plugins/pytest-csv-params/
67
+ Project-URL: Homepage, https://git.codebau.dev/pytest-plugins/pytest-csv-params
34
68
  Project-URL: Issue Tracker, https://git.codebau.dev/pytest-plugins/pytest-csv-params/issues
35
69
  Project-URL: Repository, https://git.codebau.dev/pytest-plugins/pytest-csv-params
36
70
  Project-URL: Releases, https://git.codebau.dev/pytest-plugins/pytest-csv-params/releases
@@ -93,6 +127,7 @@ Simply decorate your test method with `@csv_params` (`pytest_csv_params.decorato
93
127
  | `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` |
94
128
  | `data_casts` | `dict` (optional) | Cast Methods for the CSV Data (see "Data Casting" below) | `{ "a": int, "b": float }` |
95
129
  | `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" }` |
130
+ | `reuse_id_col` | `bool` (optional) | Allows to re-use the ID column as test data column (since 1.3.0), defaults to `False` for backwards compatibility | `True` |
96
131
 
97
132
  ## CSV Format
98
133
 
@@ -1,196 +1,197 @@
1
- ![pytest-csv-params](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/_images/pytest-csv-params.png)
2
-
3
- # pytest-csv-params
4
-
5
- A pytest plugin to parametrize data-driven tests by CSV files.
6
-
7
- [![Build Status](https://build.codebau.dev/buildStatus/icon?job=pytest-csv-params&style=flat)](https://git.codebau.dev/pytest-plugins/pytest-csv-params)
8
- [![PyPI - Downloads](https://img.shields.io/pypi/dw/pytest-csv-params?label=PyPI%20downloads&style=flat&logo=pypi)](https://pypi.org/project/pytest-csv-params/)
9
- [![PyPI - Version](https://img.shields.io/pypi/v/pytest-csv-params?label=PyPI%20version&style=flat&logo=pypi)](https://pypi.org/project/pytest-csv-params/)
10
- [![PyPI - Status](https://img.shields.io/pypi/status/pytest-csv-params?label=PyPI%20status&style=flat&logo=pypi)](https://pypi.org/project/pytest-csv-params/)
11
- [![PyPI - Format](https://img.shields.io/pypi/format/pytest-csv-params?label=PyPI%20format&style=flat&logo=pypi)](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).
1
+ ![pytest-csv-params](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/_images/pytest-csv-params.png)
2
+
3
+ # pytest-csv-params
4
+
5
+ A pytest plugin to parametrize data-driven tests by CSV files.
6
+
7
+ [![Build Status](https://build.codebau.dev/buildStatus/icon?job=pytest-csv-params&style=flat)](https://git.codebau.dev/pytest-plugins/pytest-csv-params)
8
+ [![PyPI - Downloads](https://img.shields.io/pypi/dw/pytest-csv-params?label=PyPI%20downloads&style=flat&logo=pypi)](https://pypi.org/project/pytest-csv-params/)
9
+ [![PyPI - Version](https://img.shields.io/pypi/v/pytest-csv-params?label=PyPI%20version&style=flat&logo=pypi)](https://pypi.org/project/pytest-csv-params/)
10
+ [![PyPI - Status](https://img.shields.io/pypi/status/pytest-csv-params?label=PyPI%20status&style=flat&logo=pypi)](https://pypi.org/project/pytest-csv-params/)
11
+ [![PyPI - Format](https://img.shields.io/pypi/format/pytest-csv-params?label=PyPI%20format&style=flat&logo=pypi)](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
+ | `reuse_id_col` | `bool` (optional) | Allows to re-use the ID column as test data column (since 1.3.0), defaults to `False` for backwards compatibility | `True` |
58
+
59
+ ## CSV Format
60
+
61
+ The default CSV format is:
62
+
63
+ - `\r\n` as line ending
64
+ - All non-numeric fields are surrounded by `"`
65
+ - If you need a `"` in the value, use `""` (double quote)
66
+ - Fields are separated by comma (`,`)
67
+
68
+ ## Usage Example
69
+
70
+ This example uses the CSV example from above.
71
+
72
+ ```python
73
+ from pytest_csv_params.decorator import csv_params
74
+
75
+ @csv_params(
76
+ data_file="/data/test-lib/cases/addition.csv",
77
+ id_col="ID#",
78
+ data_casts={
79
+ "part_a": int,
80
+ "part_b": int,
81
+ "expected_result": int,
82
+ },
83
+ )
84
+ def test_addition(part_a, part_b, expected_result):
85
+ assert part_a + part_b == expected_result
86
+ ```
87
+
88
+ Shorthand example (no ID col, only string values):
89
+
90
+ ```python
91
+ from pytest_csv_params.decorator import csv_params
92
+
93
+ @csv_params("/data/test-lib/cases/texts.csv")
94
+ def test_texts(text_a, text_b, text_c):
95
+ assert f"{text_a}:{text_b}" == text_c
96
+ ```
97
+
98
+ ### More complex example
99
+
100
+ 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`.
101
+
102
+ The CSV file (`tests/assets/example.csv`):
103
+
104
+ ```text
105
+ "Test ID","Bananas shipped","Single Banana Weight","Apples shipped","Single Apple Weight","Container Size"
106
+ "Order-7","1503","0.5","2545","0.25","1500"
107
+ "Order-15","101","0.55","1474","0.33","550"
108
+ ```
109
+
110
+ The Test (`tests/test_complex_example.py`):
111
+
112
+ ```python
113
+ from math import ceil
114
+ from os.path import join, dirname
115
+
116
+ from pytest_csv_params.decorator import csv_params
117
+
118
+
119
+ @csv_params(
120
+ data_file="example.csv",
121
+ base_dir=join(dirname(__file__), "assets"),
122
+ id_col="Test ID",
123
+ header_renames={
124
+ "Bananas shipped": "bananas_shipped",
125
+ "Single Banana Weight": "banana_weight",
126
+ "Apples shipped": "apples_shipped",
127
+ "Single Apple Weight": "apple_weight",
128
+ "Container Size": "container_size",
129
+ },
130
+ data_casts={
131
+ "bananas_shipped": int,
132
+ "banana_weight": float,
133
+ "apples_shipped": int,
134
+ "apple_weight": float,
135
+ "container_size": int,
136
+ },
137
+ )
138
+ def test_container_size_is_big_enough(
139
+ bananas_shipped: int, banana_weight: float, apples_shipped: int, apple_weight: float, container_size: int
140
+ ) -> None:
141
+ """
142
+ This is just an example test case for the documentation.
143
+ """
144
+
145
+ gross_weight = (banana_weight * bananas_shipped) + (apple_weight * apples_shipped)
146
+ assert ceil(gross_weight) <= container_size
147
+ ```
148
+
149
+ If you decide not to rename the columns, the test would look like this:
150
+
151
+ ```python
152
+ @csv_params(
153
+ data_file="example.csv",
154
+ base_dir=join(dirname(__file__), "assets"),
155
+ id_col="Test ID",
156
+ data_casts={
157
+ "Bananas_Shipped": int,
158
+ "Single_Banana_Weight": float,
159
+ "Apples_Shipped": int,
160
+ "Single_Apple_Weight": float,
161
+ "Container_Size": int,
162
+ },
163
+ )
164
+ def test_container_size_is_big_enough(
165
+ Bananas_Shipped: int, Single_Banana_Weight: float, Apples_Shipped: int, Single_Apple_Weight: float, Container_Size: int
166
+ ) -> None:
167
+ ...
168
+ ```
169
+
170
+ ## Changelog
171
+
172
+ - A detailed changelog is here:
173
+ [docs.codebau.dev/pytest-plugins/pytest-csv-params/pages/changelog.html](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/pages/changelog.html)
174
+
175
+ ## Bugs etc.
176
+
177
+ Please send your issues to `csv-params_issues` (at) `jued.de`. Please include the following:
178
+
179
+ - Plugin Version used
180
+ - Pytest version
181
+ - Python version with operating system
182
+
183
+ It would be great if you could include example code that clarifies your issue.
184
+
185
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
186
+
187
+ ## Pull Requests
188
+
189
+ Pull requests are always welcome. Since this Gitea instance is not open to public, just send an e-mail to discuss options.
190
+
191
+ 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.
192
+
193
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
194
+
195
+ ## Where are the sources?
196
+
197
+ The source code is available under [git.codebau.dev/pytest-plugins/pytest-csv-params](https://git.codebau.dev/pytest-plugins/pytest-csv-params).
@@ -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
+ )