punit 1.12.0__tar.gz → 1.12.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 (61) hide show
  1. {punit-1.12.0/src/pUnit.egg-info → punit-1.12.2}/PKG-INFO +9 -3
  2. {punit-1.12.0 → punit-1.12.2}/README.md +8 -2
  3. {punit-1.12.0 → punit-1.12.2}/pyproject.toml +1 -1
  4. {punit-1.12.0 → punit-1.12.2/src/pUnit.egg-info}/PKG-INFO +9 -3
  5. {punit-1.12.0 → punit-1.12.2}/src/pUnit.egg-info/SOURCES.txt +2 -2
  6. {punit-1.12.0 → punit-1.12.2}/src/punit/TextIOCapture.py +21 -23
  7. {punit-1.12.0 → punit-1.12.2}/src/punit/__init__.py +4 -6
  8. {punit-1.12.0 → punit-1.12.2}/src/punit/__main__.py +3 -0
  9. {punit-1.12.0 → punit-1.12.2}/src/punit/cli.py +19 -18
  10. punit-1.12.0/src/punit/concurrent.py → punit-1.12.2/src/punit/parallel.py +15 -12
  11. {punit-1.12.0 → punit-1.12.2}/src/punit/runner.py +64 -41
  12. punit-1.12.2/src/punit/sequential.py +63 -0
  13. punit-1.12.0/src/punit/sync.py +0 -63
  14. {punit-1.12.0 → punit-1.12.2}/LICENSE +0 -0
  15. {punit-1.12.0 → punit-1.12.2}/setup.cfg +0 -0
  16. {punit-1.12.0 → punit-1.12.2}/src/pUnit.egg-info/dependency_links.txt +0 -0
  17. {punit-1.12.0 → punit-1.12.2}/src/pUnit.egg-info/entry_points.txt +0 -0
  18. {punit-1.12.0 → punit-1.12.2}/src/pUnit.egg-info/requires.txt +0 -0
  19. {punit-1.12.0 → punit-1.12.2}/src/pUnit.egg-info/top_level.txt +0 -0
  20. {punit-1.12.0 → punit-1.12.2}/src/punit/SKILL.md +0 -0
  21. {punit-1.12.0 → punit-1.12.2}/src/punit/TestResult.py +0 -0
  22. {punit-1.12.0 → punit-1.12.2}/src/punit/assertions/__init__.py +0 -0
  23. {punit-1.12.0 → punit-1.12.2}/src/punit/assertions/collections.py +0 -0
  24. {punit-1.12.0 → punit-1.12.2}/src/punit/assertions/exceptions.py +0 -0
  25. {punit-1.12.0 → punit-1.12.2}/src/punit/assertions/numeric.py +0 -0
  26. {punit-1.12.0 → punit-1.12.2}/src/punit/assertions/strings.py +0 -0
  27. {punit-1.12.0 → punit-1.12.2}/src/punit/conditions/__init__.py +0 -0
  28. {punit-1.12.0 → punit-1.12.2}/src/punit/conditions/skip.py +0 -0
  29. {punit-1.12.0 → punit-1.12.2}/src/punit/discovery/TestModuleDiscovery.py +0 -0
  30. {punit-1.12.0 → punit-1.12.2}/src/punit/discovery/__init__.py +0 -0
  31. {punit-1.12.0 → punit-1.12.2}/src/punit/facts/Fact.py +0 -0
  32. {punit-1.12.0 → punit-1.12.2}/src/punit/facts/FactManager.py +0 -0
  33. {punit-1.12.0 → punit-1.12.2}/src/punit/facts/__init__.py +0 -0
  34. {punit-1.12.0 → punit-1.12.2}/src/punit/filters/Filter.py +0 -0
  35. {punit-1.12.0 → punit-1.12.2}/src/punit/filters/FilterManager.py +0 -0
  36. {punit-1.12.0 → punit-1.12.2}/src/punit/filters/__init__.py +0 -0
  37. {punit-1.12.0 → punit-1.12.2}/src/punit/metadata/CallableMetadata.py +0 -0
  38. {punit-1.12.0 → punit-1.12.2}/src/punit/metadata/__init__.py +0 -0
  39. {punit-1.12.0 → punit-1.12.2}/src/punit/mocks/__init__.py +0 -0
  40. {punit-1.12.0 → punit-1.12.2}/src/punit/mocks/matcher.py +0 -0
  41. {punit-1.12.0 → punit-1.12.2}/src/punit/mocks/mock.py +0 -0
  42. {punit-1.12.0 → punit-1.12.2}/src/punit/mocks/patch.py +0 -0
  43. {punit-1.12.0 → punit-1.12.2}/src/punit/py.typed +0 -0
  44. {punit-1.12.0 → punit-1.12.2}/src/punit/reports/HtmlReportGenerator.py +0 -0
  45. {punit-1.12.0 → punit-1.12.2}/src/punit/reports/JUnitReportGenerator.py +0 -0
  46. {punit-1.12.0 → punit-1.12.2}/src/punit/reports/JsonReportGenerator.py +0 -0
  47. {punit-1.12.0 → punit-1.12.2}/src/punit/reports/__init__.py +0 -0
  48. {punit-1.12.0 → punit-1.12.2}/src/punit/results/__init__.py +0 -0
  49. {punit-1.12.0 → punit-1.12.2}/src/punit/results/fails.py +0 -0
  50. {punit-1.12.0 → punit-1.12.2}/src/punit/setups/Setup.py +0 -0
  51. {punit-1.12.0 → punit-1.12.2}/src/punit/setups/SetupManager.py +0 -0
  52. {punit-1.12.0 → punit-1.12.2}/src/punit/setups/__init__.py +0 -0
  53. {punit-1.12.0 → punit-1.12.2}/src/punit/teardowns/Teardown.py +0 -0
  54. {punit-1.12.0 → punit-1.12.2}/src/punit/teardowns/TeardownManager.py +0 -0
  55. {punit-1.12.0 → punit-1.12.2}/src/punit/teardowns/__init__.py +0 -0
  56. {punit-1.12.0 → punit-1.12.2}/src/punit/theories/Theory.py +0 -0
  57. {punit-1.12.0 → punit-1.12.2}/src/punit/theories/TheoryManager.py +0 -0
  58. {punit-1.12.0 → punit-1.12.2}/src/punit/theories/__init__.py +0 -0
  59. {punit-1.12.0 → punit-1.12.2}/src/punit/traits/Trait.py +0 -0
  60. {punit-1.12.0 → punit-1.12.2}/src/punit/traits/TraitManager.py +0 -0
  61. {punit-1.12.0 → punit-1.12.2}/src/punit/traits/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pUnit
3
- Version: 1.12.0
3
+ Version: 1.12.2
4
4
  Summary: A modernized unit-test framework for Python.
5
5
  Author-email: Shaun Wilson <mrshaunwilson@msn.com>
6
6
  License-Expression: MIT
@@ -64,8 +64,9 @@ python3 -m punit --help
64
64
  ```
65
65
  Outputs:
66
66
  ```plaintext
67
- Usage: python3 -m punit [-h|--help]
68
- [-q|--quiet] [-v|--verbose]
67
+ Usage: python3 -m punit [-h|--help] [FILE ...]
68
+ [-q|--quiet]
69
+ [-v|--verbose]
69
70
  [-z|--failfast]
70
71
  [-p|--test-package NAME]
71
72
  [-i|--include PATTERN]
@@ -76,11 +77,16 @@ Usage: python3 -m punit [-h|--help]
76
77
  [-n|--no-default-patterns]
77
78
  [--no-exitcode]
78
79
  [--no-pathfix]
80
+ [--parallel [THREADS]]
79
81
  [-r|--report {junit|json}]
80
82
  [-o|--output FILENAME]
81
83
 
82
84
  Options:
83
85
  -h, --help Show this help text and exit
86
+ --parallel [THREADS]
87
+ Run tests using specified number of worker threads,
88
+ each with its own asyncio event loop. If omitted
89
+ the default is half the number of CPU cores.
84
90
  -q, --quiet Quiet output
85
91
  -v, --verbose Verbose output
86
92
  -z, --failfast Stop on first failure or error
@@ -41,8 +41,9 @@ python3 -m punit --help
41
41
  ```
42
42
  Outputs:
43
43
  ```plaintext
44
- Usage: python3 -m punit [-h|--help]
45
- [-q|--quiet] [-v|--verbose]
44
+ Usage: python3 -m punit [-h|--help] [FILE ...]
45
+ [-q|--quiet]
46
+ [-v|--verbose]
46
47
  [-z|--failfast]
47
48
  [-p|--test-package NAME]
48
49
  [-i|--include PATTERN]
@@ -53,11 +54,16 @@ Usage: python3 -m punit [-h|--help]
53
54
  [-n|--no-default-patterns]
54
55
  [--no-exitcode]
55
56
  [--no-pathfix]
57
+ [--parallel [THREADS]]
56
58
  [-r|--report {junit|json}]
57
59
  [-o|--output FILENAME]
58
60
 
59
61
  Options:
60
62
  -h, --help Show this help text and exit
63
+ --parallel [THREADS]
64
+ Run tests using specified number of worker threads,
65
+ each with its own asyncio event loop. If omitted
66
+ the default is half the number of CPU cores.
61
67
  -q, --quiet Quiet output
62
68
  -v, --verbose Verbose output
63
69
  -z, --failfast Stop on first failure or error
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pUnit"
3
- version = "1.12.0"
3
+ version = "1.12.2"
4
4
  description = "A modernized unit-test framework for Python."
5
5
  keywords = ["test", "unittest", "unit-test", "xUnit", "nUnit", "pytest"]
6
6
  authors = [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pUnit
3
- Version: 1.12.0
3
+ Version: 1.12.2
4
4
  Summary: A modernized unit-test framework for Python.
5
5
  Author-email: Shaun Wilson <mrshaunwilson@msn.com>
6
6
  License-Expression: MIT
@@ -64,8 +64,9 @@ python3 -m punit --help
64
64
  ```
65
65
  Outputs:
66
66
  ```plaintext
67
- Usage: python3 -m punit [-h|--help]
68
- [-q|--quiet] [-v|--verbose]
67
+ Usage: python3 -m punit [-h|--help] [FILE ...]
68
+ [-q|--quiet]
69
+ [-v|--verbose]
69
70
  [-z|--failfast]
70
71
  [-p|--test-package NAME]
71
72
  [-i|--include PATTERN]
@@ -76,11 +77,16 @@ Usage: python3 -m punit [-h|--help]
76
77
  [-n|--no-default-patterns]
77
78
  [--no-exitcode]
78
79
  [--no-pathfix]
80
+ [--parallel [THREADS]]
79
81
  [-r|--report {junit|json}]
80
82
  [-o|--output FILENAME]
81
83
 
82
84
  Options:
83
85
  -h, --help Show this help text and exit
86
+ --parallel [THREADS]
87
+ Run tests using specified number of worker threads,
88
+ each with its own asyncio event loop. If omitted
89
+ the default is half the number of CPU cores.
84
90
  -q, --quiet Quiet output
85
91
  -v, --verbose Verbose output
86
92
  -z, --failfast Stop on first failure or error
@@ -13,10 +13,10 @@ src/punit/TextIOCapture.py
13
13
  src/punit/__init__.py
14
14
  src/punit/__main__.py
15
15
  src/punit/cli.py
16
- src/punit/concurrent.py
16
+ src/punit/parallel.py
17
17
  src/punit/py.typed
18
18
  src/punit/runner.py
19
- src/punit/sync.py
19
+ src/punit/sequential.py
20
20
  src/punit/assertions/__init__.py
21
21
  src/punit/assertions/collections.py
22
22
  src/punit/assertions/exceptions.py
@@ -2,24 +2,7 @@
2
2
  # SPDX-License-Identifier: MIT
3
3
 
4
4
  """
5
- Module-level TextIO output capture for concurrent test execution.
6
-
7
- When tests run concurrently on a single thread, multiple coroutines write to
8
- ``sys.stdout`` / ``sys.stderr`` simultaneously and interleave or clobber each
9
- other's captures. This module fixes that by:
10
-
11
- 1. Creating two persistent ``_TextIOCapture`` instances that replace
12
- ``sys.stdout`` / ``sys.stderr`` via ``setup_global_text_io()``.
13
-
14
- 2. Using a ``contextvars.ContextVar`` to track the active
15
- ``TextIOReceiver`` pair for the current task.
16
-
17
- 3. Dispatching every ``write()`` on the persistent capture to the correct
18
- receiver based on the contextvar so that each test's output is isolated
19
- to its own ``TestResult``.
20
-
21
- The ``quiet`` passthrough to the original stream is a process-wide concern
22
- controlled by the ``_TextIOCapture``. The receiver only accumulates text.
5
+ TextIO output capture, so stdout/stderr are collected for each test.
23
6
  """
24
7
 
25
8
  from __future__ import annotations
@@ -30,7 +13,7 @@ import sys
30
13
  from typing import Any, Optional
31
14
 
32
15
  # ---------------------------------------------------------------------------
33
- # Context variable – stores the active receivers for the current task
16
+ # Context variable - stores the active receivers for the current task
34
17
  # ---------------------------------------------------------------------------
35
18
 
36
19
  _text_io_receivers_ctx: Any = contextvars.ContextVar(
@@ -45,9 +28,9 @@ class TextIOReceiver:
45
28
  The persistent ``_TextIOCapture`` dispatches all writes to whichever
46
29
  receiver is active in the current task's context (resolved via the
47
30
  contextvars.ContextVar). Each test gets its own receiver so output
48
- is never mixed between concurrent tests.
31
+ is never mixed between parallelism tests.
49
32
 
50
- The receiver knows nothing about ``quiet`` – it simply accumulates text
33
+ The receiver knows nothing about ``quiet`` - it simply accumulates text
51
34
  into its ``output`` attribute. Passthrough to the original stream is
52
35
  the responsibility of the persistent ``_TextIOCapture``.
53
36
  """
@@ -150,7 +133,7 @@ class _TextIOCapture(io.TextIOBase):
150
133
 
151
134
 
152
135
  # ---------------------------------------------------------------------------
153
- # Persistent instances – created once at module import time
136
+ # Persistent instances - created once at module import time
154
137
  # ---------------------------------------------------------------------------
155
138
 
156
139
  _PERSISTENT_STDOUT = _TextIOCapture(quiet=False, is_stdout=True)
@@ -160,7 +143,7 @@ _PERSISTENT_STDERR = _TextIOCapture(quiet=False, is_stdout=False)
160
143
  def setup_global_text_io() -> None:
161
144
  """Replace ``sys.stdout`` and ``sys.stderr`` with persistent captures.
162
145
 
163
- Called once by ``TestRunner.run()`` so both serial and concurrent paths
146
+ Called once by ``TestRunner.run()`` so both serial and parallel paths
164
147
  dispatch through the persistent capture. After this, all writes to
165
148
  stdout/stderr go through the capture which routes to the correct
166
149
  task-local ``TextIOReceiver`` via the contextvars.ContextVar.
@@ -187,3 +170,18 @@ def _clear_receivers() -> None:
187
170
  collect writes during teardown or unexpected post-test output.
188
171
  """
189
172
  _text_io_receivers_ctx.set(None)
173
+
174
+
175
+ def teardown_global_text_io() -> None:
176
+ """Detach the persistent captures and restore ``sys.stdout``/``sys.stderr``.
177
+
178
+ Calls ``_clear_receivers`` (so the contextvar is nulled) and replaces
179
+ ``sys.stdout`` / ``sys.stderr`` back to their original values.
180
+
181
+ Must be called after all tests have completed and test-result printing
182
+ is finished, so that report output and summary lines are written through
183
+ the original streams unobstructed.
184
+ """
185
+ _text_io_receivers_ctx.set(None)
186
+ sys.stdout = sys.__stdout__
187
+ sys.stderr = sys.__stderr__
@@ -14,13 +14,12 @@ from .conditions import skip
14
14
  from .teardowns import Teardown, teardown
15
15
  from .theories import theory, inlinedata
16
16
  from .traits import trait
17
- from .sync import synchronous
18
- from .concurrent import ConcurrentPool
17
+ from .sequential import sequential
19
18
 
20
19
  from . import mocks
21
20
 
22
- __version__ = '1.12.0'
23
- __commit__ = '7c3df11'
21
+ __version__ = '1.12.2'
22
+ __commit__ = '3afa951'
24
23
  __all__ = [
25
24
  '__version__', '__commit__',
26
25
  'assertions',
@@ -36,6 +35,5 @@ __all__ = [
36
35
  'trait',
37
36
  'fails',
38
37
  'skip',
39
- 'synchronous',
40
- 'ConcurrentPool',
38
+ 'sequential',
41
39
  ]
@@ -7,6 +7,7 @@ import sys
7
7
  import time
8
8
  from pathlib import Path
9
9
 
10
+ from .TextIOCapture import teardown_global_text_io
10
11
  from .cli import CommandLineInterface
11
12
  from .discovery import TestModuleDiscovery
12
13
  from .facts.FactManager import FactManager
@@ -57,6 +58,8 @@ async def async_main() -> None:
57
58
  test_runner = TestRunner(cli.test_package_name, test_module_discovery.filenames, cli)
58
59
  results = await test_runner.run()
59
60
  total_time = time.time() - start_time
61
+ # Detach IO captures so report and summary output use real stdout/stderr
62
+ teardown_global_text_io()
60
63
  failure_count = 0
61
64
  for result in results:
62
65
  if not result.is_success:
@@ -28,7 +28,7 @@ class CommandLineInterface:
28
28
  """
29
29
 
30
30
  __aliases: dict[str, str]
31
- __concurrentMode: int | None
31
+ __parallelism: int | None
32
32
  __excludePatterns: list[str]
33
33
  __excludeTraits: list[Trait]
34
34
  __failfast: bool
@@ -49,7 +49,7 @@ class CommandLineInterface:
49
49
 
50
50
  def __init__(self) -> None:
51
51
  self.__aliases = dict[str, str]()
52
- self.__concurrentMode = None
52
+ self.__parallelism = None
53
53
  self.__excludePatterns = []
54
54
  self.__excludeTraits = []
55
55
  self.__failfast = False
@@ -83,7 +83,7 @@ class CommandLineInterface:
83
83
  extractAliasPath: bool = False
84
84
  extractReportFormat: bool = False
85
85
  extractOutputFilename: bool = False
86
- extract_concurrent_mode: bool = False
86
+ extract_parallel: bool = False
87
87
  for arg in argv:
88
88
  if extractFilter:
89
89
  self.__processFilterArg(arg)
@@ -141,18 +141,18 @@ class CommandLineInterface:
141
141
  extractOutputFilename = False
142
142
  self.__outputFilename = arg
143
143
  continue
144
- if extract_concurrent_mode:
145
- extract_concurrent_mode = False
144
+ if extract_parallel:
145
+ extract_parallel = False
146
146
  try:
147
- self.__concurrentMode = int(arg)
147
+ self.__parallelism = int(arg)
148
148
  except ValueError:
149
- self.__concurrentMode = 0
149
+ self.__parallelism = 0
150
150
  continue
151
151
  match arg:
152
152
  case '-h' | '--help':
153
153
  self.__help = True
154
- case '-c' | '--concurrent-mode':
155
- extract_concurrent_mode = True
154
+ case '--parallel' | '--concurrent-mode': # NOTE: `--concurrent-mode` is a backward compatibility alias, deprecated.
155
+ extract_parallel = True
156
156
  case '-a':
157
157
  extractAliasName = True
158
158
  case '-f' | '--filter':
@@ -186,8 +186,8 @@ class CommandLineInterface:
186
186
  case _:
187
187
  continue
188
188
 
189
- if extract_concurrent_mode:
190
- self.__concurrentMode = 0
189
+ if extract_parallel:
190
+ self.__parallelism = 0
191
191
 
192
192
  if len(FilterManager.instance().filters) == 0:
193
193
  FilterManager.instance().add('*')
@@ -205,8 +205,8 @@ class CommandLineInterface:
205
205
  return self.__aliases
206
206
 
207
207
  @property
208
- def concurrent_mode(self) -> int | None:
209
- return self.__concurrentMode
208
+ def parallel(self) -> int | None:
209
+ return self.__parallelism
210
210
 
211
211
  @property
212
212
  def failfast(self) -> bool:
@@ -272,8 +272,8 @@ class CommandLineInterface:
272
272
  self.print_version()
273
273
  print("""
274
274
  Usage: python3 -m punit [-h|--help] [FILE ...]
275
- [-c|--concurrent-mode [N]]
276
- [-q|--quiet] [-v|--verbose]
275
+ [-q|--quiet]
276
+ [-v|--verbose]
277
277
  [-z|--failfast]
278
278
  [-p|--test-package NAME]
279
279
  [-i|--include PATTERN]
@@ -284,14 +284,15 @@ Usage: python3 -m punit [-h|--help] [FILE ...]
284
284
  [-n|--no-default-patterns]
285
285
  [--no-exitcode]
286
286
  [--no-pathfix]
287
+ [--parallel [THREADS]]
287
288
  [-r|--report {junit|json}]
288
289
  [-o|--output FILENAME]
289
290
 
290
291
  Options:
291
292
  -h, --help Show this help text and exit
292
- -c, --concurrent-mode [N]
293
- Run tests concurrently using up to N worker threads,
294
- each with its own asyncio event loop. If N is omitted
293
+ --parallel [THREADS]
294
+ Run tests using specified number of worker threads,
295
+ each with its own asyncio event loop. If omitted
295
296
  the default is half the number of CPU cores.
296
297
  -q, --quiet Quiet output
297
298
  -v, --verbose Verbose output
@@ -2,7 +2,7 @@
2
2
  # SPDX-License-Identifier: MIT
3
3
 
4
4
  """
5
- Concurrent test execution infrastructure for pUnit.
5
+ Parallel test execution infrastructure for pUnit.
6
6
 
7
7
  Provides a pool of worker threads, each with its own asyncio event loop,
8
8
  for executing tests in parallel.
@@ -16,9 +16,7 @@ from __future__ import annotations
16
16
 
17
17
  import asyncio
18
18
  import inspect
19
- import os
20
19
  import queue
21
- import sys
22
20
  import threading
23
21
  import time
24
22
  from types import ModuleType
@@ -39,7 +37,7 @@ class _TaskInfo:
39
37
  self.exception: BaseException | None = None
40
38
 
41
39
 
42
- class ConcurrentPool:
40
+ class ThreadPool:
43
41
  """
44
42
  Manages a pool of worker threads, each with its own asyncio event loop.
45
43
 
@@ -49,23 +47,23 @@ class ConcurrentPool:
49
47
 
50
48
  Parameters
51
49
  ----------
52
- concurrency : int
53
- Maximum number of tasks to run concurrently. This also equals the
50
+ parallelism : int
51
+ Maximum number of tasks to run in parallel. This also equals the
54
52
  number of worker threads. Must be at least 1.
55
53
  """
56
54
 
57
- def __init__(self, concurrency: int) -> None:
58
- if concurrency < 1:
59
- raise ValueError("concurrency must be at least 1")
60
- self._concurrency: int = concurrency
55
+ def __init__(self, parallelism: int) -> None:
56
+ if parallelism < 1:
57
+ raise ValueError("parallelism must be at least 1")
58
+ self._parallelism: int = parallelism
61
59
  self._loops: list[asyncio.AbstractEventLoop] = []
62
60
  self._queues: list[queue.Queue[_TaskInfo | None]] = []
63
61
  self._counter: int = 0
64
62
  self._lock: threading.Lock = threading.Lock()
65
63
  self._workers: list[threading.Thread] = []
66
64
 
67
- def __enter__(self) -> ConcurrentPool:
68
- for _ in range(self._concurrency):
65
+ def __enter__(self) -> ThreadPool:
66
+ for _ in range(self._parallelism):
69
67
  loop = asyncio.new_event_loop()
70
68
  q: queue.Queue[_TaskInfo | None] = queue.Queue()
71
69
  self._loops.append(loop)
@@ -330,3 +328,8 @@ async def _execute_theory(
330
328
  result.release_output()
331
329
 
332
330
  return result
331
+
332
+
333
+ __all__ = [
334
+ 'ThreadPool'
335
+ ]
@@ -13,7 +13,7 @@ from typing import Any, Callable, Optional
13
13
 
14
14
  from .TextIOCapture import setup_global_text_io, _PERSISTENT_STDOUT, _PERSISTENT_STDERR
15
15
  from .cli import CommandLineInterface
16
- from .concurrent import ConcurrentPool, _execute_fact, _execute_theory
16
+ from .parallel import ThreadPool, _execute_fact, _execute_theory
17
17
  from .facts.FactManager import FactManager
18
18
  from .setups.SetupManager import SetupManager
19
19
  from .teardowns.TeardownManager import TeardownManager
@@ -37,19 +37,19 @@ def _get_skip_condition(target: Any) -> bool | Callable[..., bool] | None:
37
37
  return None
38
38
 
39
39
 
40
- def _is_synchronous(target: Any) -> bool:
41
- """Return True if *target* is marked with ``@synchronous``."""
40
+ def _is_sequential(target: Any) -> bool:
41
+ """Return True if *target* is marked with ``@sequential``."""
42
42
  unwrapped = inspect.unwrap(target)
43
- return getattr(unwrapped, '__punit_synchronous', None) is True
43
+ return getattr(unwrapped, '__punit_sequential', None) is True
44
44
 
45
45
 
46
- def _get_concurrency(cli: 'CommandLineInterface') -> int:
47
- """Resolve the concurrency level from CLI.
46
+ def _get_parallelism(cli: 'CommandLineInterface') -> int:
47
+ """Resolve the parallelism level from CLI.
48
48
 
49
- Returns ``-1`` when concurrent mode is disabled (use sequential flow).
49
+ Returns ``-1`` when parallel mode is disabled (use sequential flow).
50
50
  Returns the worker count when enabled; ``0`` maps to ``cpu_count // 2``.
51
51
  """
52
- mode = cli.concurrent_mode
52
+ mode = cli.parallel
53
53
  if mode is None:
54
54
  return -1
55
55
  if mode <= 0:
@@ -276,17 +276,17 @@ class TestRunner:
276
276
  results: list[TestResult] = []
277
277
  result: TestResult
278
278
  # TODO: aliasing
279
- # Install persistent TextIO captures so both serial and concurrent
279
+ # Install persistent TextIO captures so both serial and parallel
280
280
  # paths dispatch writes to the correct task-local receivers.
281
281
  setup_global_text_io()
282
282
  # Set quiet passthrough on the global captures based on CLI
283
283
  _PERSISTENT_STDOUT.quiet = self.__cli.quiet
284
284
  _PERSISTENT_STDERR.quiet = self.__cli.quiet
285
285
  test_package_path = os.path.join(os.path.abspath(os.curdir), self.__test_package_name).replace('\\', '/')
286
- concurrency = _get_concurrency(self.__cli)
286
+ parallelism = _get_parallelism(self.__cli)
287
287
 
288
- if concurrency > 0:
289
- return await self._run_concurrent(results, test_package_path)
288
+ if parallelism > 0:
289
+ return await self._run_parallel(results, test_package_path)
290
290
 
291
291
  for filename in self.__filenames:
292
292
  ts = time.time()
@@ -330,15 +330,15 @@ class TestRunner:
330
330
  return results
331
331
 
332
332
  # ------------------------------------------------------------------
333
- # Concurrent execution
333
+ # Parallel execution
334
334
  # ------------------------------------------------------------------
335
335
 
336
- async def _run_concurrent(self, results: list[TestResult], test_package_path: str) -> list[TestResult]:
336
+ async def _run_parallel(self, results: list[TestResult], test_package_path: str) -> list[TestResult]:
337
337
  """Execute all tests with a worker pool (each worker has its own event loop)."""
338
- concurrency = _get_concurrency(self.__cli)
339
- pool: ConcurrentPool | None = None
338
+ parallelism = _get_parallelism(self.__cli)
339
+ pool: ThreadPool | None = None
340
340
  try:
341
- pool = ConcurrentPool(concurrency)
341
+ pool = ThreadPool(parallelism)
342
342
  with pool:
343
343
  module_report_name = ''
344
344
  for filename in self.__filenames:
@@ -356,16 +356,16 @@ class TestRunner:
356
356
  test_module = importlib.import_module(module_import_name, self.__test_package_name)
357
357
  host_name = socket.gethostname()
358
358
 
359
- await self._run_concurrent_facts(host_name, test_module, filename, module_report_name, results, pool)
359
+ await self._run_parallel_facts(host_name, test_module, filename, module_report_name, results, pool)
360
360
  if self.__cli.failfast and any(e.is_success is False for e in results):
361
361
  break
362
362
 
363
- await self._run_concurrent_theories(host_name, test_module, filename, module_report_name, results, pool)
363
+ await self._run_parallel_theories(host_name, test_module, filename, module_report_name, results, pool)
364
364
  if self.__cli.failfast and any(e.is_success is False for e in results):
365
365
  break
366
366
 
367
- await self._run_synchronous_facts(host_name, test_module, filename, module_report_name, results, pool)
368
- await self._run_synchronous_theories(host_name, test_module, filename, module_report_name, results, pool)
367
+ await self._run_sequential_facts(host_name, test_module, filename, module_report_name, results, pool)
368
+ await self._run_sequential_theories(host_name, test_module, filename, module_report_name, results, pool)
369
369
 
370
370
  except Exception as ex:
371
371
  result = TestResult()
@@ -384,14 +384,20 @@ class TestRunner:
384
384
  pass
385
385
  return results
386
386
 
387
- async def _run_concurrent_facts(self, host_name: str, test_module: ModuleType, filename: str,
388
- module_report_name: str, results: list[TestResult],
389
- pool: ConcurrentPool) -> None:
390
- """Run non-synchronous facts concurrently via the worker pool."""
387
+ async def _run_parallel_facts(
388
+ self,
389
+ host_name: str,
390
+ test_module: ModuleType,
391
+ filename: str,
392
+ module_report_name: str,
393
+ results: list[TestResult],
394
+ pool: ThreadPool
395
+ ) -> None:
396
+ """Run non-sequential facts in parallel via thread pool."""
391
397
  facts = FactManager.instance().get(test_module.__name__)
392
398
  coros: list[Any] = []
393
399
  for fact in facts:
394
- if _is_synchronous(fact.target):
400
+ if _is_sequential(fact.target):
395
401
  continue
396
402
  coro = _execute_fact(fact, test_module, module_report_name, filename, host_name, self.__test_package_name)
397
403
  coros.append(coro)
@@ -403,15 +409,20 @@ class TestRunner:
403
409
  if self.__cli.failfast and not test_result.is_success:
404
410
  return
405
411
 
406
- async def _run_concurrent_theories(self, host_name: str, test_module: ModuleType, filename: str,
407
- module_report_name: str, results: list[TestResult],
408
- pool: ConcurrentPool) -> None:
409
- """Run non-synchronous theory data-points concurrently."""
412
+ async def _run_parallel_theories(
413
+ self,
414
+ host_name: str,
415
+ test_module: ModuleType,
416
+ filename: str,
417
+ module_report_name: str, results: list[TestResult],
418
+ pool: ThreadPool
419
+ ) -> None:
420
+ """Run non-sequential theory data-points concurrently."""
410
421
  theories = TheoryManager.instance().get(test_module.__name__)
411
422
  coros: list[Any] = []
412
423
  for theory in theories:
413
424
  for data in theory.datas:
414
- if _is_synchronous(theory.target):
425
+ if _is_sequential(theory.target):
415
426
  continue
416
427
  coro = _execute_theory(theory, data, test_module, module_report_name, filename, host_name, self.__test_package_name)
417
428
  coros.append(coro)
@@ -423,13 +434,19 @@ class TestRunner:
423
434
  if self.__cli.failfast and not test_result.is_success:
424
435
  return
425
436
 
426
- async def _run_synchronous_facts(self, host_name: str, test_module: ModuleType, filename: str,
427
- module_report_name: str, results: list[TestResult],
428
- pool: ConcurrentPool) -> None:
429
- """Run @synchronous facts sequentially."""
437
+ async def _run_sequential_facts(
438
+ self,
439
+ host_name: str,
440
+ test_module: ModuleType,
441
+ filename: str,
442
+ module_report_name: str,
443
+ results: list[TestResult],
444
+ pool: ThreadPool
445
+ ) -> None:
446
+ """Run @sequential facts sequentially."""
430
447
  facts = FactManager.instance().get(test_module.__name__)
431
448
  for fact in facts:
432
- if not _is_synchronous(fact.target):
449
+ if not _is_sequential(fact.target):
433
450
  continue
434
451
  test_result = await _execute_fact(fact, test_module, module_report_name, filename, host_name, self.__test_package_name)
435
452
  results.append(test_result)
@@ -437,13 +454,19 @@ class TestRunner:
437
454
  if self.__cli.failfast and not test_result.is_success:
438
455
  return
439
456
 
440
- async def _run_synchronous_theories(self, host_name: str, test_module: ModuleType, filename: str,
441
- module_report_name: str, results: list[TestResult],
442
- pool: ConcurrentPool) -> None:
443
- """Run @synchronous theory data-points sequentially."""
457
+ async def _run_sequential_theories(
458
+ self,
459
+ host_name: str,
460
+ test_module: ModuleType,
461
+ filename: str,
462
+ module_report_name: str,
463
+ results: list[TestResult],
464
+ pool: ThreadPool
465
+ ) -> None:
466
+ """Run @sequential theory data-points sequentially."""
444
467
  theories = TheoryManager.instance().get(test_module.__name__)
445
468
  for theory in theories:
446
- if not _is_synchronous(theory.target):
469
+ if not _is_sequential(theory.target):
447
470
  continue
448
471
  for data in theory.datas:
449
472
  test_result = await _execute_theory(theory, data, test_module, module_report_name, filename, host_name, self.__test_package_name)
@@ -0,0 +1,63 @@
1
+ # SPDX-FileCopyrightText: © 2024 Shaun Wilson
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """
5
+ ``@sequential`` decorator for pUnit.
6
+
7
+ When running tests with ``--parallel``, any test decorated with
8
+ ``@sequential`` is deferred to a sequential pass that runs after all
9
+ parallel peers at the same scope have finished.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from typing import Any, Callable
15
+
16
+
17
+ def sequential(target: Callable[..., Any]) -> Callable[..., Any]:
18
+ """Mark a test function or method for **sequential** (sequential) execution.
19
+
20
+ When pUnit is started with ``--parralel THREADS`` (where *THREADS* > 1),
21
+ tests decorated without ``@sequential`` run in parallel up to *N* at
22
+ any given point. ``@sequential`` tests are **not** added to the
23
+ concurrent dispatch queue -- after all peers at the same scope finish
24
+ concurrently, the sequential tests run one after another in their
25
+ definition order.
26
+
27
+ The decorator returns the original ``target`` unchanged; it installs the
28
+ ``__punit_sequential`` marker attribute on the unwrapped function.
29
+
30
+ Parameters
31
+ ----------
32
+ target : Callable
33
+ The test function or method to mark.
34
+
35
+ Returns
36
+ -------
37
+ Callable
38
+ The original, undecorated target.
39
+
40
+ Example
41
+ -------
42
+
43
+ .. code-block:: python
44
+
45
+ from punit import fact, sequential
46
+
47
+ @fact
48
+ @sequential
49
+ def my_test():
50
+ assert True
51
+
52
+ class MyTestCase:
53
+ @fact
54
+ @sequential
55
+ def test_one(self):
56
+ assert True
57
+
58
+ """
59
+ import inspect
60
+
61
+ unwrapped = inspect.unwrap(target)
62
+ setattr(unwrapped, "__punit_sequential", True)
63
+ return target
@@ -1,63 +0,0 @@
1
- # SPDX-FileCopyrightText: © 2024 Shaun Wilson
2
- # SPDX-License-Identifier: MIT
3
-
4
- """
5
- ``@synchronous`` decorator for pUnit.
6
-
7
- When running tests with ``--concurrent-mode``, any test decorated with
8
- ``@synchronous`` is deferred to a sequential pass that runs after all
9
- concurrent peers at the same scope have finished.
10
- """
11
-
12
- from __future__ import annotations
13
-
14
- from typing import Callable
15
-
16
-
17
- def synchronous(target: Callable) -> Callable:
18
- """Mark a test function or method for **synchronous** (sequential) execution.
19
-
20
- When pUnit is started with ``--concurrent-mode N`` (where *N* > 1),
21
- tests decorated without ``@synchronous`` run in parallel up to *N* at
22
- any given point. ``@synchronous`` tests are **not** added to the
23
- concurrent dispatch queue -- after all peers at the same scope finish
24
- concurrently, the synchronous tests run one after another in their
25
- definition order.
26
-
27
- The decorator returns the original ``target`` unchanged; it installs the
28
- ``__punit_synchronous`` marker attribute on the unwrapped function.
29
-
30
- Parameters
31
- ----------
32
- target : Callable
33
- The test function or method to mark.
34
-
35
- Returns
36
- -------
37
- Callable
38
- The original, undecorated target.
39
-
40
- Example
41
- -------
42
-
43
- .. code-block:: python
44
-
45
- from punit import fact, synchronous
46
-
47
- @fact
48
- @synchronous
49
- def my_test():
50
- assert True
51
-
52
- class MyTestCase:
53
- @fact
54
- @synchronous
55
- def test_one(self):
56
- assert True
57
-
58
- """
59
- import inspect
60
-
61
- unwrapped = inspect.unwrap(target)
62
- setattr(unwrapped, "__punit_synchronous", True)
63
- return target
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes