unittest-parametrize 1.4.0__py3-none-any.whl → 1.6.0__py3-none-any.whl

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.
@@ -2,11 +2,11 @@ from __future__ import annotations
2
2
 
3
3
  import inspect
4
4
  import sys
5
+ from collections.abc import Sequence
5
6
  from functools import wraps
6
7
  from types import FunctionType
7
8
  from typing import Any
8
9
  from typing import Callable
9
- from typing import Sequence
10
10
  from typing import TypeVar
11
11
  from unittest import TestCase
12
12
 
@@ -40,15 +40,49 @@ class ParametrizedTestCase(TestCase):
40
40
  for param in _parametrized.params:
41
41
  params = dict(zip(_parametrized.argnames, param.args))
42
42
 
43
- @wraps(func)
44
- def test(
45
- self: TestCase,
46
- *args: Any,
47
- _func: FunctionType = func,
48
- _params: dict[str, Any] = params,
49
- **kwargs: Any,
50
- ) -> Any:
51
- return _func(self, *args, **_params, **kwargs)
43
+ if inspect.iscoroutinefunction(func):
44
+
45
+ @wraps(func)
46
+ async def test(
47
+ self: TestCase,
48
+ *args: Any,
49
+ _func: FunctionType = func,
50
+ _params: dict[str, Any] = params,
51
+ **kwargs: Any,
52
+ ) -> Any:
53
+ try:
54
+ return await _func(self, *args, **_params, **kwargs)
55
+ except Exception as exc:
56
+ if sys.version_info >= (3, 11):
57
+ exc.add_note(
58
+ "Test parameters: "
59
+ + ", ".join(
60
+ f"{k}={v!r}" for k, v in _params.items()
61
+ )
62
+ )
63
+ raise
64
+
65
+ else:
66
+
67
+ @wraps(func)
68
+ def test(
69
+ self: TestCase,
70
+ *args: Any,
71
+ _func: FunctionType = func,
72
+ _params: dict[str, Any] = params,
73
+ **kwargs: Any,
74
+ ) -> Any:
75
+ try:
76
+ return _func(self, *args, **_params, **kwargs)
77
+ except Exception as exc:
78
+ if sys.version_info >= (3, 11):
79
+ exc.add_note(
80
+ "Test parameters: "
81
+ + ", ".join(
82
+ f"{k}={v!r}" for k, v in _params.items()
83
+ )
84
+ )
85
+ raise
52
86
 
53
87
  test.__name__ = f"{name}_{param.id}"
54
88
  test.__qualname__ = f"{test.__qualname__}_{param.id}"
@@ -135,7 +169,7 @@ def parametrize(
135
169
  )
136
170
 
137
171
  _parametrized = parametrized(argnames, params)
138
- bind_kwargs = {k: None for k in _parametrized.argnames}
172
+ bind_kwargs = dict.fromkeys(_parametrized.argnames)
139
173
 
140
174
  def wrapper(func: Callable[P, T]) -> Callable[P, T]:
141
175
  # Check given argnames will work
@@ -1,37 +1,33 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unittest-parametrize
3
- Version: 1.4.0
3
+ Version: 1.6.0
4
4
  Summary: Parametrize tests within unittest TestCases.
5
- Home-page: https://github.com/adamchainz/unittest-parametrize
6
- Author: Adam Johnson
7
- Author-email: me@adamj.eu
8
- License: MIT
5
+ Author-email: Adam Johnson <me@adamj.eu>
9
6
  Project-URL: Changelog, https://github.com/adamchainz/unittest-parametrize/blob/main/CHANGELOG.rst
10
- Project-URL: Mastodon, https://fosstodon.org/@adamchainz
11
- Project-URL: Twitter, https://twitter.com/adamchainz
7
+ Project-URL: Funding, https://adamj.eu/books/
8
+ Project-URL: Repository, https://github.com/adamchainz/unittest-parametrize
12
9
  Keywords: unittest
13
10
  Classifier: Development Status :: 5 - Production/Stable
14
11
  Classifier: Intended Audience :: Developers
15
12
  Classifier: License :: OSI Approved :: MIT License
16
13
  Classifier: Natural Language :: English
17
- Classifier: Programming Language :: Python :: 3
18
14
  Classifier: Programming Language :: Python :: 3 :: Only
19
- Classifier: Programming Language :: Python :: 3.8
20
15
  Classifier: Programming Language :: Python :: 3.9
21
16
  Classifier: Programming Language :: Python :: 3.10
22
17
  Classifier: Programming Language :: Python :: 3.11
23
18
  Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
24
20
  Classifier: Typing :: Typed
25
- Requires-Python: >=3.8
21
+ Requires-Python: >=3.9
26
22
  Description-Content-Type: text/x-rst
27
23
  License-File: LICENSE
28
- Requires-Dist: typing-extensions ; python_version < "3.10"
24
+ Requires-Dist: typing-extensions; python_version < "3.10"
29
25
 
30
26
  ====================
31
27
  unittest-parametrize
32
28
  ====================
33
29
 
34
- .. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/unittest-parametrize/main.yml?branch=main&style=for-the-badge
30
+ .. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/unittest-parametrize/main.yml.svg?branch=main&style=for-the-badge
35
31
  :target: https://github.com/adamchainz/unittest-parametrize/actions?workflow=CI
36
32
 
37
33
  .. image:: https://img.shields.io/pypi/v/unittest-parametrize.svg?style=for-the-badge
@@ -46,6 +42,13 @@ unittest-parametrize
46
42
 
47
43
  Parametrize tests within unittest TestCases.
48
44
 
45
+ ----
46
+
47
+ **Testing a Django project?**
48
+ Check out my book `Speed Up Your Django Tests <https://adamchainz.gumroad.com/l/suydt>`__ which covers loads of recommendations to write faster, more accurate tests.
49
+
50
+ ----
51
+
49
52
  Installation
50
53
  ============
51
54
 
@@ -55,14 +58,7 @@ Install with:
55
58
 
56
59
  python -m pip install unittest-parametrize
57
60
 
58
- Python 3.8 to 3.12 supported.
59
-
60
- ----
61
-
62
- **Testing a Django project?**
63
- Check out my book `Speed Up Your Django Tests <https://adamchainz.gumroad.com/l/suydt>`__ which covers loads of recommendations to write faster, more accurate tests.
64
-
65
- ----
61
+ Python 3.9 to 3.13 supported.
66
62
 
67
63
  Usage
68
64
  =====
@@ -77,7 +73,7 @@ __ https://docs.pytest.org/en/stable/how-to/parametrize.html#parametrize-basics
77
73
  There are two steps to parametrize a test case:
78
74
 
79
75
  1. Use ``ParametrizedTestCase`` in the base classes for your test case.
80
- 2. Apply ``@parametrize`` to any tests for parametrization.
76
+ 2. Apply ``@parametrize`` to any test methods for parametrization.
81
77
  This decorator takes (at least):
82
78
 
83
79
  * the argument names to parametrize, as comma-separated string
@@ -105,6 +101,7 @@ Here’s a basic example:
105
101
  ``@parametrize`` modifies the class at definition time with Python’s |__init_subclass__ hook|__.
106
102
  It removes the original test method and creates wrapped copies with individual names.
107
103
  Thus the parametrization should work regardless of the test runner you use (be it unittest, Django’s test runner, pytest, etc.).
104
+ It supports both synchronous and asynchronous test methods.
108
105
 
109
106
  .. |__init_subclass__ hook| replace:: ``__init_subclass__`` hook
110
107
  __ https://docs.python.org/3/reference/datamodel.html#object.__init_subclass__
@@ -0,0 +1,7 @@
1
+ unittest_parametrize/__init__.py,sha256=-WNbay-GoS2_ENp9cOgE3pf_BJH2Nr1eX7wiAwJyxic,6299
2
+ unittest_parametrize/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ unittest_parametrize-1.6.0.dist-info/LICENSE,sha256=Jn179RflkRZXhSCGt_D7asLy2Ex47C0WdBHxe0lBazk,1069
4
+ unittest_parametrize-1.6.0.dist-info/METADATA,sha256=kZJe0NHStrHyHJgkttwwmGgBOagnfB4XfffeK_SspUI,15223
5
+ unittest_parametrize-1.6.0.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
6
+ unittest_parametrize-1.6.0.dist-info/top_level.txt,sha256=4nLqNaGtBX8Ny36ZdFt37Gk-87hPtOvfdfZlTBi3OtU,21
7
+ unittest_parametrize-1.6.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: setuptools (75.7.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- unittest_parametrize/__init__.py,sha256=NOM_rtblvEKHKU07icuyi9VI25hH46Emft2yvQUsJuU,4818
2
- unittest_parametrize/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- unittest_parametrize-1.4.0.dist-info/LICENSE,sha256=Jn179RflkRZXhSCGt_D7asLy2Ex47C0WdBHxe0lBazk,1069
4
- unittest_parametrize-1.4.0.dist-info/METADATA,sha256=e0JyTXpSMHl8w_tIROe3o19rGt7c_hkPBEiIYcLwyQ0,15269
5
- unittest_parametrize-1.4.0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
6
- unittest_parametrize-1.4.0.dist-info/top_level.txt,sha256=4nLqNaGtBX8Ny36ZdFt37Gk-87hPtOvfdfZlTBi3OtU,21
7
- unittest_parametrize-1.4.0.dist-info/RECORD,,