pytest-csv-params 2.1.1__tar.gz → 2.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.
Files changed (21) hide show
  1. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/.gitignore +6 -0
  2. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/PKG-INFO +17 -2
  3. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/README.md +16 -1
  4. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/_ptcsvp/parametrize.py +14 -1
  5. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pyproject.toml +1 -1
  6. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pytest_csv_params/types.py +7 -1
  7. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/LICENSE.txt +0 -0
  8. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/_ptcsvp/__init__.py +0 -0
  9. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/_ptcsvp/cmdline.py +0 -0
  10. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/_ptcsvp/configure.py +0 -0
  11. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/_ptcsvp/exception.py +0 -0
  12. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/_ptcsvp/plugin.py +0 -0
  13. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/_ptcsvp/varname.py +0 -0
  14. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/_ptcsvp/version.py +0 -0
  15. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pytest_csv_params/__init__.py +0 -0
  16. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pytest_csv_params/decorator.py +0 -0
  17. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pytest_csv_params/dialect.py +0 -0
  18. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pytest_csv_params/exception.py +0 -0
  19. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pytest_csv_params/plugin.py +0 -0
  20. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pytest_csv_params/shortcut.py +0 -0
  21. {pytest_csv_params-2.1.1 → pytest_csv_params-2.2.0}/pytest_csv_params/warning.py +0 -0
@@ -232,3 +232,9 @@ fabric.properties
232
232
 
233
233
  # Android studio 3.1+ serialized cache file
234
234
  .idea/caches/build_file_checksums.ser
235
+
236
+ # Python formatter
237
+ .ruff-cache/
238
+
239
+ # Working on a Mac?
240
+ .DS_Store
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pytest-csv-params
3
- Version: 2.1.1
3
+ Version: 2.2.0
4
4
  Summary: Pytest plugin for Test Case Parametrization with CSV files
5
5
  Project-URL: repository, https://git.codebau.dev/pytest-plugins/pytest-csv-params
6
6
  Project-URL: homepage, https://git.codebau.dev/pytest-plugins/pytest-csv-params
@@ -34,12 +34,13 @@ Requires-Python: <3.16,>=3.10
34
34
  Requires-Dist: pytest<10,>=8.3
35
35
  Description-Content-Type: text/markdown
36
36
 
37
- ![pytest-csv-params](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/_images/pytest-csv-params.png)
37
+ from typing import Dict![pytest-csv-params](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/_images/pytest-csv-params.png)
38
38
 
39
39
  # pytest-csv-params
40
40
 
41
41
  A pytest plugin to parametrize data-driven tests by CSV files.
42
42
 
43
+ ![Build Status](https://build.codebau.dev/buildStatus/icon?job=pytest-csv-params&subject=CI+Pipeline)
43
44
  [![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/)
44
45
  [![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/)
45
46
  [![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/)
@@ -100,6 +101,7 @@ Simply decorate your test method with `@csv_params` (`pytest_csv_params.decorato
100
101
  | `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` |
101
102
  | `skip_when_missing_csv_file` | `bool` (optional) | When the CSV data cannot be loaded, the test will be skipped (since 2.1.0), defaults to `False` for backwards compatibility | `True` |
102
103
  | `skip_when_empty_csv_file` | `bool` (optional) | When the CSV data file is empty, the test will be skipped (since 2.1.0), defaults to `False` for backwards compatibility | `True` |
104
+ | `parameters_as_dictionary` | `str` (optional) | Instead of using one method argument per column, all columns are provided in the dict named with this parameter (since 2.2.0) | `test_data` |
103
105
 
104
106
  ## CSV Format
105
107
 
@@ -140,6 +142,19 @@ def test_texts(text_a, text_b, text_c):
140
142
  assert f"{text_a}:{text_b}" == text_c
141
143
  ```
142
144
 
145
+ Use a dictionary instead of multiple arguments:
146
+
147
+ ```python
148
+ from pytest_csv_params.decorator import csv_params
149
+
150
+ @csv_params(
151
+ data_file="/data/test-lib/cases/texts.csv",
152
+ parameters_as_dictionary="test_data",
153
+ )
154
+ def test_texts(test_data: dict):
155
+ assert f"{test_data['text_a']}:{test_data['text_b']}" == test_data['text_c']
156
+ ```
157
+
143
158
  ### More complex example
144
159
 
145
160
  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`.
@@ -1,9 +1,10 @@
1
- ![pytest-csv-params](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/_images/pytest-csv-params.png)
1
+ from typing import Dict![pytest-csv-params](https://docs.codebau.dev/pytest-plugins/pytest-csv-params/_images/pytest-csv-params.png)
2
2
 
3
3
  # pytest-csv-params
4
4
 
5
5
  A pytest plugin to parametrize data-driven tests by CSV files.
6
6
 
7
+ ![Build Status](https://build.codebau.dev/buildStatus/icon?job=pytest-csv-params&subject=CI+Pipeline)
7
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/)
8
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/)
9
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/)
@@ -64,6 +65,7 @@ Simply decorate your test method with `@csv_params` (`pytest_csv_params.decorato
64
65
  | `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` |
65
66
  | `skip_when_missing_csv_file` | `bool` (optional) | When the CSV data cannot be loaded, the test will be skipped (since 2.1.0), defaults to `False` for backwards compatibility | `True` |
66
67
  | `skip_when_empty_csv_file` | `bool` (optional) | When the CSV data file is empty, the test will be skipped (since 2.1.0), defaults to `False` for backwards compatibility | `True` |
68
+ | `parameters_as_dictionary` | `str` (optional) | Instead of using one method argument per column, all columns are provided in the dict named with this parameter (since 2.2.0) | `test_data` |
67
69
 
68
70
  ## CSV Format
69
71
 
@@ -104,6 +106,19 @@ def test_texts(text_a, text_b, text_c):
104
106
  assert f"{text_a}:{text_b}" == text_c
105
107
  ```
106
108
 
109
+ Use a dictionary instead of multiple arguments:
110
+
111
+ ```python
112
+ from pytest_csv_params.decorator import csv_params
113
+
114
+ @csv_params(
115
+ data_file="/data/test-lib/cases/texts.csv",
116
+ parameters_as_dictionary="test_data",
117
+ )
118
+ def test_texts(test_data: dict):
119
+ assert f"{test_data['text_a']}:{test_data['text_b']}" == test_data['text_c']
120
+ ```
121
+
107
122
  ### More complex example
108
123
 
109
124
  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`.
@@ -4,7 +4,7 @@ Parametrize a test function by CSV file
4
4
 
5
5
  import csv
6
6
  from pathlib import Path
7
- from typing import Any, List, Optional, TypedDict
7
+ from typing import Any, List, Optional, TypedDict, Dict
8
8
  from warnings import warn
9
9
 
10
10
  import pytest
@@ -27,6 +27,7 @@ from pytest_csv_params.types import (
27
27
  HeaderRenames,
28
28
  IdColName,
29
29
  SkipConfig,
30
+ DictionaryName,
30
31
  )
31
32
  from pytest_csv_params.warning import CsvParamsOnlyOneColumnIsUsedAsIdAndDataWarning
32
33
 
@@ -110,6 +111,7 @@ def add_parametrization( # pylint: disable=too-many-arguments
110
111
  reuse_id_col: bool = False,
111
112
  skip_when_missing_csv_file: SkipConfig = None,
112
113
  skip_when_empty_csv_file: SkipConfig = None,
114
+ parameters_as_dictionary: DictionaryName = None,
113
115
  ) -> MarkDecorator:
114
116
  """
115
117
  Parametrize a test function with data from a CSV file.
@@ -125,6 +127,7 @@ def add_parametrization( # pylint: disable=too-many-arguments
125
127
  :param reuse_id_col: Allows re-using the ID col as test data column; defaults to `False` for backwards compatibility
126
128
  :param skip_when_missing_csv_file: Let tests automatically skip when CSV source is missing (since 2.1.0)
127
129
  :param skip_when_empty_csv_file: Let tests automatically skip when CSV source does not contain any test data (since 2.1.0)
130
+ :param parameters_as_dictionary: Instead of using one argument per field, all arguments are passed as a dictionary with the given name (since 2.2.0)
128
131
 
129
132
  :returns: :meth:`pytest.mark.parametrize` mark decorator, filled with all the data from the CSV.
130
133
  """
@@ -195,6 +198,16 @@ def add_parametrization( # pylint: disable=too-many-arguments
195
198
  id_data = None
196
199
  if id_col is not None:
197
200
  id_data = [tc_data["test_id"] for tc_data in data]
201
+ if parameters_as_dictionary is not None:
202
+ param_header_name = make_name_valid(parameters_as_dictionary)
203
+ list_of_dicts: List[Dict[str, Any]] = []
204
+ for tc_element in [tc_data["data"] for tc_data in data]:
205
+ list_of_dicts.append(dict(zip(headers, tc_element)))
206
+ return pytest.mark.parametrize(
207
+ param_header_name,
208
+ [pytest.param(d) for d in list_of_dicts],
209
+ ids=id_data,
210
+ )
198
211
  return pytest.mark.parametrize(
199
212
  headers, [tc_data["data"] for tc_data in data], ids=id_data
200
213
  )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytest-csv-params"
3
- version = "2.1.1"
3
+ version = "2.2.0"
4
4
  description = "Pytest plugin for Test Case Parametrization with CSV files"
5
5
  authors = [
6
6
  { name = "Juergen Edelbluth", email = "csv_params@jued.de" },
@@ -67,6 +67,12 @@ The :class:`HeaderRenames` describes the type of the `header_renames` parameter
67
67
 
68
68
  SkipConfig = Optional[bool]
69
69
  """
70
- The :class:`SkipWhenMissingCSVFile` describes the type of the `skip_when_missing_csv_files` parameter of the
70
+ The :class:`SkipWhenMissingCSVFile` describes the type of the `skip_when_*_csv_files` parameter of the
71
71
  :meth:`~pytest_csv_params.decorator.csv_params` decorator. It is just an optional :class:`bool`.
72
72
  """
73
+
74
+ DictionaryName = Optional[str]
75
+ """
76
+ The :class:`DictionaryName` describes the type of the `parameters_as_dictionary` parameter of the
77
+ :meth:`~pytest_csv_params.decorator.csv_params` decorator. It is just an optional :class:`str`.
78
+ """