unittest-parametrize 1.5.0__tar.gz → 1.6.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.
@@ -2,6 +2,13 @@
2
2
  Changelog
3
3
  =========
4
4
 
5
+ 1.6.0 (2025-01-06)
6
+ ------------------
7
+
8
+ * Add suport for asynchronous tests.
9
+
10
+ Thanks to Adrien Cossa in `PR #121 <https://github.com/adamchainz/unittest-parametrize/pull/121>`__.
11
+
5
12
  1.5.0 (2024-10-08)
6
13
  ------------------
7
14
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unittest-parametrize
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Parametrize tests within unittest TestCases.
5
5
  Author-email: Adam Johnson <me@adamj.eu>
6
6
  Project-URL: Changelog, https://github.com/adamchainz/unittest-parametrize/blob/main/CHANGELOG.rst
@@ -73,7 +73,7 @@ __ https://docs.pytest.org/en/stable/how-to/parametrize.html#parametrize-basics
73
73
  There are two steps to parametrize a test case:
74
74
 
75
75
  1. Use ``ParametrizedTestCase`` in the base classes for your test case.
76
- 2. Apply ``@parametrize`` to any tests for parametrization.
76
+ 2. Apply ``@parametrize`` to any test methods for parametrization.
77
77
  This decorator takes (at least):
78
78
 
79
79
  * the argument names to parametrize, as comma-separated string
@@ -101,6 +101,7 @@ Here’s a basic example:
101
101
  ``@parametrize`` modifies the class at definition time with Python’s |__init_subclass__ hook|__.
102
102
  It removes the original test method and creates wrapped copies with individual names.
103
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.
104
105
 
105
106
  .. |__init_subclass__ hook| replace:: ``__init_subclass__`` hook
106
107
  __ https://docs.python.org/3/reference/datamodel.html#object.__init_subclass__
@@ -48,7 +48,7 @@ __ https://docs.pytest.org/en/stable/how-to/parametrize.html#parametrize-basics
48
48
  There are two steps to parametrize a test case:
49
49
 
50
50
  1. Use ``ParametrizedTestCase`` in the base classes for your test case.
51
- 2. Apply ``@parametrize`` to any tests for parametrization.
51
+ 2. Apply ``@parametrize`` to any test methods for parametrization.
52
52
  This decorator takes (at least):
53
53
 
54
54
  * the argument names to parametrize, as comma-separated string
@@ -76,6 +76,7 @@ Here’s a basic example:
76
76
  ``@parametrize`` modifies the class at definition time with Python’s |__init_subclass__ hook|__.
77
77
  It removes the original test method and creates wrapped copies with individual names.
78
78
  Thus the parametrization should work regardless of the test runner you use (be it unittest, Django’s test runner, pytest, etc.).
79
+ It supports both synchronous and asynchronous test methods.
79
80
 
80
81
  .. |__init_subclass__ hook| replace:: ``__init_subclass__`` hook
81
82
  __ https://docs.python.org/3/reference/datamodel.html#object.__init_subclass__
@@ -6,7 +6,7 @@ requires = [
6
6
 
7
7
  [project]
8
8
  name = "unittest-parametrize"
9
- version = "1.5.0"
9
+ version = "1.6.0"
10
10
  description = "Parametrize tests within unittest TestCases."
11
11
  readme = "README.rst"
12
12
  keywords = [
@@ -40,23 +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
- try:
52
- return _func(self, *args, **_params, **kwargs)
53
- except Exception as exc:
54
- if sys.version_info >= (3, 11):
55
- exc.add_note(
56
- "Test parameters: "
57
- + ", ".join(f"{k}={v!r}" for k, v in _params.items())
58
- )
59
- raise
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
60
86
 
61
87
  test.__name__ = f"{name}_{param.id}"
62
88
  test.__qualname__ = f"{test.__qualname__}_{param.id}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unittest-parametrize
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Parametrize tests within unittest TestCases.
5
5
  Author-email: Adam Johnson <me@adamj.eu>
6
6
  Project-URL: Changelog, https://github.com/adamchainz/unittest-parametrize/blob/main/CHANGELOG.rst
@@ -73,7 +73,7 @@ __ https://docs.pytest.org/en/stable/how-to/parametrize.html#parametrize-basics
73
73
  There are two steps to parametrize a test case:
74
74
 
75
75
  1. Use ``ParametrizedTestCase`` in the base classes for your test case.
76
- 2. Apply ``@parametrize`` to any tests for parametrization.
76
+ 2. Apply ``@parametrize`` to any test methods for parametrization.
77
77
  This decorator takes (at least):
78
78
 
79
79
  * the argument names to parametrize, as comma-separated string
@@ -101,6 +101,7 @@ Here’s a basic example:
101
101
  ``@parametrize`` modifies the class at definition time with Python’s |__init_subclass__ hook|__.
102
102
  It removes the original test method and creates wrapped copies with individual names.
103
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.
104
105
 
105
106
  .. |__init_subclass__ hook| replace:: ``__init_subclass__`` hook
106
107
  __ https://docs.python.org/3/reference/datamodel.html#object.__init_subclass__