pytest-check 3.0.2__tar.gz → 3.1.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 (108) hide show
  1. {pytest_check-3.0.2 → pytest_check-3.1.0}/.coveragerc +1 -0
  2. {pytest_check-3.0.2 → pytest_check-3.1.0}/.github/workflows/main.yml +1 -1
  3. {pytest_check-3.0.2 → pytest_check-3.1.0}/PKG-INFO +3 -4
  4. {pytest_check-3.0.2 → pytest_check-3.1.0}/README.md +1 -1
  5. {pytest_check-3.0.2 → pytest_check-3.1.0}/changelog.md +34 -0
  6. pytest_check-3.1.0/examples/test_example_context_manager_messages.py +54 -0
  7. {pytest_check-3.0.2 → pytest_check-3.1.0}/pyproject.toml +2 -3
  8. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/check_log.py +18 -2
  9. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/check_raises.py +1 -1
  10. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/context_manager.py +4 -2
  11. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/plugin.py +21 -0
  12. pytest_check-3.1.0/tests/test_assertion_colors.py +35 -0
  13. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_check_context_manager.py +29 -0
  14. pytest_check-3.1.0/tests/test_isolated_asyncio.py +15 -0
  15. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_raises.py +26 -0
  16. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_thread.py +58 -1
  17. {pytest_check-3.0.2 → pytest_check-3.1.0}/tox.ini +2 -1
  18. pytest_check-3.0.2/tests/test_isolated_asyncio.py +0 -6
  19. {pytest_check-3.0.2 → pytest_check-3.1.0}/.github/.deployment.md +0 -0
  20. {pytest_check-3.0.2 → pytest_check-3.1.0}/.github/FUNDING.yml +0 -0
  21. {pytest_check-3.0.2 → pytest_check-3.1.0}/.github/workflows/publish-to-pypi.yml +0 -0
  22. {pytest_check-3.0.2 → pytest_check-3.1.0}/.gitignore +0 -0
  23. {pytest_check-3.0.2 → pytest_check-3.1.0}/LICENSE.txt +0 -0
  24. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/logging_to_a_file/conftest.py +0 -0
  25. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/logging_to_a_file/test_file_logging.py +0 -0
  26. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_alt_names.py +0 -0
  27. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_any_failures.py +0 -0
  28. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_check_and_assert.py +0 -0
  29. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_check_check.py +0 -0
  30. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_check_func_decorator.py +0 -0
  31. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_check_func_xfail.py +0 -0
  32. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_check_not_in_test.py +0 -0
  33. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_context_functions.py +0 -0
  34. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_context_manager_fail.py +0 -0
  35. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_context_manager_pass.py +0 -0
  36. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_context_manager_type.py +0 -0
  37. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_fail_func.py +0 -0
  38. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_fail_in_fixture.py +0 -0
  39. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_fail_in_teardown_with_skip.py +0 -0
  40. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_fail_in_thread.py +0 -0
  41. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_functions_fail.py +0 -0
  42. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_functions_pass.py +0 -0
  43. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_functions_xfail.py +0 -0
  44. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_helpers.py +0 -0
  45. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_httpx.py +0 -0
  46. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_isolated_asyncio.py +0 -0
  47. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_locals.py +0 -0
  48. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_logging.py +0 -0
  49. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_loop.py +0 -0
  50. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_maxfail.py +0 -0
  51. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_message.py +0 -0
  52. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_mix_checks_and_assertions.py +0 -0
  53. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_multi.py +0 -0
  54. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_multi_check_raises.py +0 -0
  55. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_multiple_failures.py +0 -0
  56. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_mypy.py +0 -0
  57. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_mypy_fail.py +0 -0
  58. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_non_assert_exceptions.py +0 -0
  59. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_parallel_threads.py +0 -0
  60. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_pass_in_thread.py +0 -0
  61. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_raises.py +0 -0
  62. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_simple.py +0 -0
  63. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_speedup_funcs.py +0 -0
  64. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_stop_on_fail.py +0 -0
  65. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_summary.py +0 -0
  66. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_tb_style.py +0 -0
  67. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_traceback.py +0 -0
  68. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_tracebackhide.py +0 -0
  69. {pytest_check-3.0.2 → pytest_check-3.1.0}/examples/test_example_xfail.py +0 -0
  70. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/__init__.py +0 -0
  71. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/__init__.pyi +0 -0
  72. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/check_functions.py +0 -0
  73. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/pseudo_traceback.py +0 -0
  74. {pytest_check-3.0.2 → pytest_check-3.1.0}/src/pytest_check/py.typed +0 -0
  75. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/__init__.py +0 -0
  76. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/conftest.py +0 -0
  77. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/markers.py +0 -0
  78. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_alt_names.py +0 -0
  79. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_any_failures.py +0 -0
  80. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_check_and_assert.py +0 -0
  81. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_check_check.py +0 -0
  82. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_check_fixture.py +0 -0
  83. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_check_func_decorator.py +0 -0
  84. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_fail_func.py +0 -0
  85. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_fail_in_fixture.py +0 -0
  86. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_fail_in_teardown_with_skip.py +0 -0
  87. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_func_xfail.py +0 -0
  88. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_functions.py +0 -0
  89. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_helpers.py +0 -0
  90. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_locals.py +0 -0
  91. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_logging.py +0 -0
  92. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_maxfail.py +0 -0
  93. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_message.py +0 -0
  94. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_non_assert_exceptions.py +0 -0
  95. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_not_in_test.py +0 -0
  96. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_parallel_threads.py +0 -0
  97. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_pseudo_tb_corner_cases.py +0 -0
  98. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_red.py +0 -0
  99. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_reportlog.py +0 -0
  100. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_speedup_flags.py +0 -0
  101. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_speedup_functions.py +0 -0
  102. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_stop_on_fail.py +0 -0
  103. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_summary.py +0 -0
  104. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_tb_line.py +0 -0
  105. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_tb_style.py +0 -0
  106. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_thread_runner_compat.py +0 -0
  107. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_tracebackhide.py +0 -0
  108. {pytest_check-3.0.2 → pytest_check-3.1.0}/tests/test_xfail.py +0 -0
@@ -1,5 +1,6 @@
1
1
  [run]
2
2
  branch = True
3
+ patch = subprocess
3
4
 
4
5
  [paths]
5
6
  source =
@@ -16,7 +16,7 @@ jobs:
16
16
  runs-on: ubuntu-latest
17
17
  strategy:
18
18
  matrix:
19
- python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.14t", "3.15", "3.15t"]
19
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t", "3.15", "3.15t"]
20
20
 
21
21
  steps:
22
22
  - uses: actions/checkout@v5
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pytest-check
3
- Version: 3.0.2
3
+ Version: 3.1.0
4
4
  Summary: A pytest plugin that allows multiple failures per test.
5
5
  Project-URL: Home, https://github.com/okken/pytest-check
6
6
  Author: Brian Okken
@@ -30,7 +30,6 @@ Classifier: Development Status :: 5 - Production/Stable
30
30
  Classifier: Framework :: Pytest
31
31
  Classifier: Intended Audience :: Developers
32
32
  Classifier: Programming Language :: Python
33
- Classifier: Programming Language :: Python :: 3.9
34
33
  Classifier: Programming Language :: Python :: 3.10
35
34
  Classifier: Programming Language :: Python :: 3.11
36
35
  Classifier: Programming Language :: Python :: 3.12
@@ -39,7 +38,7 @@ Classifier: Programming Language :: Python :: 3.14
39
38
  Classifier: Programming Language :: Python :: 3.15
40
39
  Classifier: Topic :: Software Development :: Testing
41
40
  Classifier: Topic :: Utilities
42
- Requires-Python: >=3.9
41
+ Requires-Python: >=3.10
43
42
  Requires-Dist: packaging
44
43
  Requires-Dist: pytest>=7.0.0
45
44
  Requires-Dist: typing-extensions<5,>=4.12.2; python_version < '3.11'
@@ -396,7 +395,7 @@ You can turn off the failure reports with pytests `--tb=no`.
396
395
 
397
396
  Setting `-x` or `--maxfail=1` will cause this plugin to abort testing after the first failed check.
398
397
 
399
- Setting `-maxfail=2` or greater will turn off any handling of maxfail within this plugin and the behavior is controlled by pytest.
398
+ Setting `--maxfail=2` or greater will turn off any handling of maxfail within this plugin and the behavior is controlled by pytest.
400
399
 
401
400
  In other words, the `maxfail` count is counting tests, not checks.
402
401
  The exception is the case of `1`, where we want to stop on the very first failed check.
@@ -345,7 +345,7 @@ You can turn off the failure reports with pytests `--tb=no`.
345
345
 
346
346
  Setting `-x` or `--maxfail=1` will cause this plugin to abort testing after the first failed check.
347
347
 
348
- Setting `-maxfail=2` or greater will turn off any handling of maxfail within this plugin and the behavior is controlled by pytest.
348
+ Setting `--maxfail=2` or greater will turn off any handling of maxfail within this plugin and the behavior is controlled by pytest.
349
349
 
350
350
  In other words, the `maxfail` count is counting tests, not checks.
351
351
  The exception is the case of `1`, where we want to stop on the very first failed check.
@@ -47,6 +47,40 @@ TEMPLATE_END
47
47
 
48
48
  -->
49
49
 
50
+ ## [3.1.0] - 17-Nov-2026
51
+
52
+ ### Removed
53
+
54
+ - Support for Python 3.9
55
+ - pytest now requires 3.10+, so we may as well also
56
+
57
+ ### Fixed
58
+
59
+ - Release completed thread context wrappers without requiring cyclic garbage
60
+ collection, preserving existing run overrides and cleaning up failed starts (#217).
61
+ - Keep custom check context messages separate when contexts are nested, saved for later, or used in different threads (#215).
62
+ - Preserve pytest's source highlighting for assertions that fail after a soft
63
+ check, retaining both failure reports (#216).
64
+ - `check.raises()` no longer consumes a generator or other one-shot iterable of
65
+ expected exceptions while validating it (#214).
66
+ - README: corrected the `--maxfail` option spelling.
67
+
68
+ ### Developer Experience
69
+
70
+ - Coverage environment now installs `pytest-xdist` and measures subprocesses
71
+ (`patch = subprocess` in `.coveragerc`), so code paths that only run in
72
+ xdist workers are covered.
73
+
74
+ ## [3.0.3] - 14-Oct-2026
75
+
76
+ ### Fixed
77
+
78
+ - Second attempt to fix issue #210.
79
+ - First attempt "seemed" fixed in the context of the in-process pytest runner, but failed as a subprocess.
80
+ - I've added a subprocess run, and a fix.
81
+ - Pretty sure it's fixed now.
82
+
83
+
50
84
  ## [3.0.2] - 13-Oct-2026
51
85
 
52
86
  ### Fixed
@@ -0,0 +1,54 @@
1
+ from threading import Event, Thread
2
+
3
+ from pytest_check import check
4
+
5
+
6
+ def test_nested_messages():
7
+ with check("outer message"):
8
+ with check("inner message"):
9
+ raise AssertionError("inner failure")
10
+ raise AssertionError("outer failure")
11
+
12
+
13
+ def test_saved_messages():
14
+ first = check("first message")
15
+ second = check("second message")
16
+ with first:
17
+ raise AssertionError("first failure")
18
+ with second:
19
+ raise AssertionError("second failure")
20
+
21
+
22
+ def test_thread_messages():
23
+ entered_first = Event()
24
+ entered_second = Event()
25
+ finished_first = Event()
26
+
27
+ def first():
28
+ with check("first message"):
29
+ entered_first.set()
30
+ assert entered_second.wait(5)
31
+ raise AssertionError("first failure")
32
+ finished_first.set()
33
+
34
+ def second():
35
+ assert entered_first.wait(5)
36
+ with check("second message"):
37
+ entered_second.set()
38
+ assert finished_first.wait(5)
39
+ raise AssertionError("second failure")
40
+
41
+ threads = [Thread(target=first), Thread(target=second)]
42
+ for thread in threads:
43
+ thread.start()
44
+ for thread in threads:
45
+ thread.join(timeout=10)
46
+ assert not thread.is_alive()
47
+
48
+
49
+ def test_bound_helpers():
50
+ with check("custom message") as context:
51
+ assert context.equal(1, 1)
52
+ assert not context.any_failures()
53
+ with check:
54
+ assert True
@@ -4,14 +4,13 @@ authors = [{ name = "Brian Okken" }]
4
4
  readme = "README.md"
5
5
  license = { file = "LICENSE.txt" }
6
6
  description = "A pytest plugin that allows multiple failures per test."
7
- version = "3.0.2"
8
- requires-python = ">=3.9"
7
+ version = "3.1.0"
8
+ requires-python = ">=3.10"
9
9
  classifiers = [
10
10
  'Development Status :: 5 - Production/Stable',
11
11
  'Framework :: Pytest',
12
12
  'Intended Audience :: Developers',
13
13
  'Programming Language :: Python',
14
- 'Programming Language :: Python :: 3.9',
15
14
  'Programming Language :: Python :: 3.10',
16
15
  'Programming Language :: Python :: 3.11',
17
16
  'Programming Language :: Python :: 3.12',
@@ -171,16 +171,32 @@ def _propagate_context_to_new_threads() -> None:
171
171
  child_state = _current_state().new_child()
172
172
  ctx = contextvars.copy_context()
173
173
  original_run = self.run
174
+ had_run_override = "run" in self.__dict__
175
+
176
+ def restore_run() -> None:
177
+ if had_run_override:
178
+ self.__dict__["run"] = original_run
179
+ else:
180
+ self.__dict__.pop("run", None)
174
181
 
175
182
  def run_in_context() -> None:
176
183
  def body() -> None:
177
184
  _state_var.set(child_state)
178
185
  original_run()
179
186
 
180
- ctx.run(body)
187
+ try:
188
+ ctx.run(body)
189
+ finally:
190
+ # The wrapper closes over the thread's bound run method.
191
+ # Remove that reference even if its body raises.
192
+ restore_run()
181
193
 
182
194
  self.run = run_in_context # type: ignore[method-assign] # ty: ignore[invalid-assignment]
183
- original_start(self)
195
+ try:
196
+ original_start(self)
197
+ except BaseException:
198
+ restore_run()
199
+ raise
184
200
 
185
201
  threading.Thread.start = start_with_context # type: ignore[method-assign]
186
202
 
@@ -51,7 +51,7 @@ def raises(
51
51
  if isinstance(expected_exception, type):
52
52
  expected_exceptions: Iterable[type] = (expected_exception,)
53
53
  else:
54
- expected_exceptions = expected_exception
54
+ expected_exceptions = tuple(expected_exception)
55
55
 
56
56
  assert all(
57
57
  isinstance(exc, type) or issubclass(exc, BaseException)
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
  import warnings
3
+ import copy
3
4
  import traceback
4
5
  from types import TracebackType
5
6
  from typing import Any, Callable, Type
@@ -45,8 +46,9 @@ class CheckContextManager:
45
46
  return None
46
47
 
47
48
  def __call__(self, msg: object = None) -> "CheckContextManager":
48
- self.msg = msg
49
- return self
49
+ configured = copy.copy(self)
50
+ configured.msg = msg
51
+ return configured
50
52
 
51
53
  def __getattr__(self, name: str) -> Any:
52
54
  """Allow type-checkers to accept dynamically attached helper attributes."""
@@ -63,6 +63,7 @@ def pytest_runtest_makereport(
63
63
  report.wasxfail = xfailed_value.reason
64
64
  else:
65
65
  summary = f"Failed Checks: {num_failures}"
66
+ original_longrepr = report.longrepr
66
67
  longrepr = ["\n".join(failures), "-" * 60, summary]
67
68
 
68
69
  if report.longrepr:
@@ -111,6 +112,22 @@ def pytest_runtest_makereport(
111
112
  # it works.
112
113
  ...
113
114
 
115
+ if isinstance(original_longrepr, ExceptionChainRepr):
116
+ # Keep pytest's source-aware renderer for a simultaneous
117
+ # assertion/exception instead of flattening it into text.
118
+ checks_crash = original_longrepr.reprcrash
119
+ if isinstance(report.longrepr, ExceptionChainRepr):
120
+ checks_crash = report.longrepr.reprcrash
121
+ combined = ExceptionChainRepr(
122
+ [
123
+ (ReprTraceback([], None, "auto"), checks_crash, "\n".join(longrepr[:3])),
124
+ *original_longrepr.chain,
125
+ ]
126
+ )
127
+ combined.reprcrash = checks_crash
128
+ combined.sections.extend(original_longrepr.sections)
129
+ report.longrepr = combined
130
+
114
131
  call.excinfo = excinfo
115
132
 
116
133
 
@@ -167,6 +184,10 @@ def _match_exception(exc_name: str, failures: list[str]) -> bool:
167
184
 
168
185
 
169
186
  def pytest_configure(config: Config) -> None:
187
+ # IsolatedAsyncioTestCase snapshots the current context when its test case
188
+ # is created during collection. Seed the state before that snapshot.
189
+ check_log.clear_failures()
190
+
170
191
  # Add some red to the failure output, if stdout can accommodate it.
171
192
  isatty = sys.stdout.isatty()
172
193
  color = getattr(config.option, "color", None)
@@ -0,0 +1,35 @@
1
+ import re
2
+
3
+ import pytest
4
+
5
+
6
+ @pytest.mark.parametrize("color", ["yes", "no"])
7
+ @pytest.mark.parametrize("workers", [0, 2])
8
+ def test_mixed_check_and_assert_keep_source_highlighting(pytester, color, workers):
9
+ if color == "yes":
10
+ pytest.importorskip("pygments")
11
+ if workers:
12
+ pytest.importorskip("xdist")
13
+ pytester.makepyfile(
14
+ """
15
+ from pytest_check import check
16
+
17
+ def test_mixed():
18
+ value = 1
19
+ check.equal(value, 2)
20
+ assert value == 3
21
+ """
22
+ )
23
+ arguments = [f"--color={color}", "--code-highlight=yes"]
24
+ if workers:
25
+ arguments.extend(["-n", str(workers)])
26
+ result = pytester.runpytest(*arguments)
27
+ result.assert_outcomes(failed=1)
28
+ output = result.stdout.str()
29
+ assert "Failed Checks: 1" in output
30
+ assert "check 1 == 2" in output
31
+ if color == "yes":
32
+ assert re.search(r"\x1b\[[0-9;]*massert\x1b\[[0-9;]*m", output)
33
+ else:
34
+ assert "assert value == 3" in output
35
+ assert "\x1b[" not in output
@@ -48,3 +48,32 @@ def test_context_manager_shows_custom_messages_on_failure(
48
48
  assert "first fail" in str(result.stdout)
49
49
  assert "second fail" in str(result.stdout)
50
50
  assert "third fail" in str(result.stdout)
51
+
52
+
53
+ def test_nested_context_messages_remain_separate(run_example_test: Callable) -> None:
54
+ result = run_example_test("test_example_context_manager_messages.py", "nested_messages")
55
+ result.assert_outcomes(failed=1)
56
+ result.stdout.fnmatch_lines(
57
+ ["*FAILURE: inner failure, inner message*", "*FAILURE: outer failure, outer message*"]
58
+ )
59
+
60
+
61
+ def test_saved_context_messages_remain_separate(run_example_test: Callable) -> None:
62
+ result = run_example_test("test_example_context_manager_messages.py", "saved_messages")
63
+ result.assert_outcomes(failed=1)
64
+ result.stdout.fnmatch_lines(
65
+ ["*FAILURE: first failure, first message*", "*FAILURE: second failure, second message*"]
66
+ )
67
+
68
+
69
+ def test_thread_context_messages_remain_separate(run_example_test: Callable) -> None:
70
+ result = run_example_test("test_example_context_manager_messages.py", "thread_messages")
71
+ result.assert_outcomes(failed=1)
72
+ result.stdout.fnmatch_lines(
73
+ ["*FAILURE: first failure, first message*", "*FAILURE: second failure, second message*"]
74
+ )
75
+
76
+
77
+ def test_configured_context_keeps_bound_helpers(run_example_test: Callable) -> None:
78
+ result = run_example_test("test_example_context_manager_messages.py", "bound_helpers")
79
+ result.assert_outcomes(passed=1)
@@ -0,0 +1,15 @@
1
+ from typing import TYPE_CHECKING, Callable
2
+
3
+ if TYPE_CHECKING:
4
+ from _pytest.pytester import Pytester
5
+
6
+
7
+ def test_isolated_asyncio(run_example_test: Callable) -> None:
8
+ result = run_example_test("test_example_isolated_asyncio.py")
9
+ result.assert_outcomes(failed=1)
10
+
11
+
12
+ def test_isolated_asyncio_in_subprocess(pytester: "Pytester") -> None:
13
+ pytester.copy_example("examples/test_example_isolated_asyncio.py")
14
+ result = pytester.runpytest_subprocess()
15
+ result.assert_outcomes(failed=1)
@@ -42,6 +42,32 @@ def test_raises_with_assertion_error():
42
42
  assert 0
43
43
 
44
44
 
45
+ @pytest.mark.parametrize('callable_form', [False, True])
46
+ def test_raises_with_exception_iterator(testdir, callable_form):
47
+ testdir.makepyfile(
48
+ """
49
+ from pytest_check import raises
50
+
51
+ def raise_error():
52
+ raise ValueError('expected')
53
+
54
+ def test_expected():
55
+ expected = iter([TypeError, ValueError])
56
+ if CALLABLE_FORM:
57
+ raises(expected, raise_error)
58
+ else:
59
+ with raises(expected):
60
+ raise_error()
61
+
62
+ def test_unexpected():
63
+ with raises(iter([TypeError])):
64
+ raise_error()
65
+ """.replace('CALLABLE_FORM', repr(callable_form))
66
+ )
67
+ result = testdir.runpytest()
68
+ result.assert_outcomes(passed=1, failed=1)
69
+
70
+
45
71
  def test_raises_with_multiple_errors(testdir):
46
72
  with raises((_TestException, AnotherTestException)):
47
73
  raise _TestException
@@ -1,8 +1,65 @@
1
- from threading import Barrier, Thread
1
+ import gc
2
+ import threading
3
+ from threading import Barrier, Thread, Timer
4
+ import weakref
5
+
6
+ import pytest
2
7
 
3
8
  from pytest_check import check, check_log
4
9
 
5
10
 
11
+ @pytest.mark.parametrize("timer", [False, True])
12
+ def test_finished_threads_do_not_need_garbage_collection(timer):
13
+ was_enabled = gc.isenabled()
14
+ gc.disable()
15
+ try:
16
+ thread = Timer(60, lambda: None) if timer else Thread(target=lambda: None)
17
+ reference = weakref.ref(thread)
18
+ thread.start()
19
+ if isinstance(thread, Timer):
20
+ thread.cancel()
21
+ thread.join()
22
+ del thread
23
+ assert reference() is None
24
+ finally:
25
+ if was_enabled: # pragma: no branch
26
+ gc.enable()
27
+
28
+
29
+ def test_thread_run_override_is_restored():
30
+ thread = Thread()
31
+
32
+ def original_run():
33
+ pass
34
+ thread.__dict__["run"] = original_run
35
+ thread.start()
36
+ thread.join()
37
+ assert thread.run is original_run
38
+
39
+
40
+ def test_failed_thread_start_does_not_leave_wrapper():
41
+ thread = Thread(target=lambda: None)
42
+ thread.start()
43
+ thread.join()
44
+ with pytest.raises(RuntimeError, match="once"):
45
+ thread.start()
46
+ assert "run" not in thread.__dict__
47
+
48
+
49
+ def test_thread_run_is_restored_after_error(monkeypatch):
50
+ errors = []
51
+ monkeypatch.setattr(threading, "excepthook", lambda args: errors.append(args.exc_type))
52
+
53
+ def fail():
54
+ raise ValueError("thread failed")
55
+
56
+ thread = Thread(target=fail)
57
+ thread.start()
58
+ thread.join()
59
+ assert errors == [ValueError]
60
+ assert "run" not in thread.__dict__
61
+
62
+
6
63
  def test_failing_threaded_testcode(pytester):
7
64
  pytester.copy_example("examples/test_example_fail_in_thread.py")
8
65
  result = pytester.runpytest()
@@ -3,11 +3,11 @@ requires =
3
3
  tox-uv>=1.28.1
4
4
  tox>=4.30.0
5
5
  env_list =
6
- py39
7
6
  py310
8
7
  py311
9
8
  py312
10
9
  py313
10
+ py314
11
11
  py314t
12
12
  py315
13
13
  py315t
@@ -60,6 +60,7 @@ description = Combine coverage from standard and thread-runner test environments
60
60
  deps =
61
61
  coverage
62
62
  pytest-reportlog
63
+ pytest-xdist
63
64
  base_python = python3.13
64
65
  setenv =
65
66
  COVERAGE_FILE = {tox_root}/.tox/coverage-py313/.coverage
@@ -1,6 +0,0 @@
1
- from typing import Callable
2
-
3
-
4
- def test_isolated_asyncio(run_example_test: Callable) -> None:
5
- result = run_example_test("test_example_isolated_asyncio.py")
6
- result.assert_outcomes(failed=1)
File without changes
File without changes