executable-stories-pytest 0.1.1__py3-none-any.whl → 0.2.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.
- executable_stories/_plugin.py +7 -0
- executable_stories/_story_api.py +34 -1
- executable_stories/_types.py +2 -0
- {executable_stories_pytest-0.1.1.dist-info → executable_stories_pytest-0.2.0.dist-info}/METADATA +1 -1
- executable_stories_pytest-0.2.0.dist-info/RECORD +12 -0
- {executable_stories_pytest-0.1.1.dist-info → executable_stories_pytest-0.2.0.dist-info}/WHEEL +1 -1
- executable_stories_pytest-0.1.1.dist-info/RECORD +0 -12
- {executable_stories_pytest-0.1.1.dist-info → executable_stories_pytest-0.2.0.dist-info}/entry_points.txt +0 -0
- {executable_stories_pytest-0.1.1.dist-info → executable_stories_pytest-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {executable_stories_pytest-0.1.1.dist-info → executable_stories_pytest-0.2.0.dist-info}/top_level.txt +0 -0
executable_stories/_plugin.py
CHANGED
|
@@ -172,6 +172,13 @@ def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo[None]) ->
|
|
|
172
172
|
if report.when != "call":
|
|
173
173
|
return
|
|
174
174
|
|
|
175
|
+
# A red test shows how far its story got without opening the report. A
|
|
176
|
+
# section, not longrepr, so the recorded error message stays as it was.
|
|
177
|
+
if report.failed:
|
|
178
|
+
trail = story._step_trail()
|
|
179
|
+
if trail:
|
|
180
|
+
report.sections.append(("Story steps", trail))
|
|
181
|
+
|
|
175
182
|
start_ms = _test_start_times.pop(item.nodeid, 0.0)
|
|
176
183
|
now_ms = time.time() * 1000
|
|
177
184
|
duration_ms = now_ms - start_ms if start_ms else 0.0
|
executable_stories/_story_api.py
CHANGED
|
@@ -49,6 +49,8 @@ class _StoryContext:
|
|
|
49
49
|
"timer_counter",
|
|
50
50
|
"otel_spans",
|
|
51
51
|
"planned",
|
|
52
|
+
"started_at_ms",
|
|
53
|
+
"failed_step",
|
|
52
54
|
)
|
|
53
55
|
|
|
54
56
|
def __init__(
|
|
@@ -76,6 +78,9 @@ class _StoryContext:
|
|
|
76
78
|
self.timer_counter: int = 0
|
|
77
79
|
self.otel_spans: list[dict[str, Any]] | None = None
|
|
78
80
|
self.planned: bool = False
|
|
81
|
+
self.started_at_ms: float = time.time() * 1000
|
|
82
|
+
# The wrapped step whose body raised, if one did.
|
|
83
|
+
self.failed_step: dict[str, Any] | None = None
|
|
79
84
|
|
|
80
85
|
|
|
81
86
|
class Story:
|
|
@@ -246,8 +251,29 @@ class Story:
|
|
|
246
251
|
result["docs"] = list(ctx.docs)
|
|
247
252
|
if ctx.otel_spans:
|
|
248
253
|
result["otelSpans"] = ctx.otel_spans
|
|
254
|
+
# A planned scenario never ran, so it has no start time.
|
|
255
|
+
if not ctx.planned:
|
|
256
|
+
result["startedAtMs"] = ctx.started_at_ms
|
|
249
257
|
return result
|
|
250
258
|
|
|
259
|
+
def _step_trail(self) -> str | None:
|
|
260
|
+
"""The story's steps as a checklist for a failed test's report.
|
|
261
|
+
|
|
262
|
+
The failing step is the wrapped step whose body raised, else the last
|
|
263
|
+
step: a marker states a claim and the assertion that broke follows it.
|
|
264
|
+
When the last step is a wrapped body that finished, the failure came
|
|
265
|
+
after it.
|
|
266
|
+
"""
|
|
267
|
+
ctx = self._ctx
|
|
268
|
+
if ctx is None or not ctx.steps:
|
|
269
|
+
return None
|
|
270
|
+
last = ctx.steps[-1]
|
|
271
|
+
failed = ctx.failed_step or (None if last.get("wrapped") else last)
|
|
272
|
+
lines = [f" {'✗' if s is failed else '✓'} {s['keyword']} {s['text']}" for s in ctx.steps]
|
|
273
|
+
if failed is None:
|
|
274
|
+
lines.append(" ✗ (failed after the last step)")
|
|
275
|
+
return "\n".join(lines)
|
|
276
|
+
|
|
251
277
|
def _get_attachments(self) -> list[dict[str, Any]]:
|
|
252
278
|
"""Return the attachments list for the current test."""
|
|
253
279
|
ctx = self._ctx
|
|
@@ -279,13 +305,15 @@ class Story:
|
|
|
279
305
|
ctx = self._ctx
|
|
280
306
|
if ctx is None:
|
|
281
307
|
raise RuntimeError(f"story.{keyword.lower()}() called before story.init()")
|
|
308
|
+
# A new step means the test caught an earlier wrapped step's exception.
|
|
309
|
+
ctx.failed_step = None
|
|
282
310
|
# Auto-And: repeated primary keywords render as "And"
|
|
283
311
|
if keyword in ("Given", "When", "Then"):
|
|
284
312
|
if keyword in ctx.seen_primary_keywords:
|
|
285
313
|
keyword = "And"
|
|
286
314
|
else:
|
|
287
315
|
ctx.seen_primary_keywords.add(keyword)
|
|
288
|
-
step: dict[str, Any] = {"keyword": keyword, "text": text}
|
|
316
|
+
step: dict[str, Any] = {"keyword": keyword, "text": text, "startedAtMs": time.time() * 1000}
|
|
289
317
|
step["id"] = f"step-{ctx.step_counter}"
|
|
290
318
|
ctx.step_counter += 1
|
|
291
319
|
if mode is not None:
|
|
@@ -370,6 +398,11 @@ class Story:
|
|
|
370
398
|
try:
|
|
371
399
|
result = body()
|
|
372
400
|
return result
|
|
401
|
+
except BaseException:
|
|
402
|
+
# A nested step that raised first keeps the mark.
|
|
403
|
+
if ctx.failed_step is None:
|
|
404
|
+
ctx.failed_step = step
|
|
405
|
+
raise
|
|
373
406
|
finally:
|
|
374
407
|
step["durationMs"] = (time.perf_counter() - start) * 1000.0
|
|
375
408
|
|
executable_stories/_types.py
CHANGED
|
@@ -189,6 +189,7 @@ class StoryStep(TypedDict):
|
|
|
189
189
|
# An absent key means unobserved, which is not the same as zero.
|
|
190
190
|
assertions: NotRequired[int]
|
|
191
191
|
durationMs: NotRequired[float]
|
|
192
|
+
startedAtMs: NotRequired[float]
|
|
192
193
|
docs: NotRequired[list[DocEntry]]
|
|
193
194
|
|
|
194
195
|
|
|
@@ -205,6 +206,7 @@ class StoryMeta(TypedDict):
|
|
|
205
206
|
suitePath: NotRequired[list[str]]
|
|
206
207
|
docs: NotRequired[list[DocEntry]]
|
|
207
208
|
sourceOrder: NotRequired[int]
|
|
209
|
+
startedAtMs: NotRequired[float]
|
|
208
210
|
|
|
209
211
|
|
|
210
212
|
# ── RawTestCase ────────────────────────────────────────────────────
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
executable_stories/__init__.py,sha256=X-m5x5nt_kkzd8IGJZ52e6lfr6aDArhbXci9K0fLWLM,132
|
|
2
|
+
executable_stories/_collector.py,sha256=gYQKlNTYpcCaNiTDbJXEV4IDWC4T7mF9zxqBz0zx_6k,1508
|
|
3
|
+
executable_stories/_json_writer.py,sha256=FrRuskUN93R-0vVermZTfskv6GZ9Aj6E-khwvmEjnH8,987
|
|
4
|
+
executable_stories/_plugin.py,sha256=IwhqMkrxjsJ9PFSyOFRRmeXTuUNSZ0VqRpcR-vpnguM,16199
|
|
5
|
+
executable_stories/_story_api.py,sha256=u3I__cTQr_5h_2Z6vD_3ZZzO3xfPj1-DlnftkCYCwgY,29517
|
|
6
|
+
executable_stories/_types.py,sha256=un-CvxwyX1KfO3Mf5RQxWkEqqkN9yuHwbA1zDCEEV6I,7459
|
|
7
|
+
executable_stories_pytest-0.2.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
8
|
+
executable_stories_pytest-0.2.0.dist-info/METADATA,sha256=E7d16fEgeTeoFioCBrcuE0uH4_0HnWbTlzZJp26NAgI,4546
|
|
9
|
+
executable_stories_pytest-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
executable_stories_pytest-0.2.0.dist-info/entry_points.txt,sha256=NXzZqAD31EI6q3ovbbWQE7VOzsok09tPpmd-QPgSTiE,59
|
|
11
|
+
executable_stories_pytest-0.2.0.dist-info/top_level.txt,sha256=0CmAUpeJrtl-ykfogdr3L373JMtP92uU1P7-GIlbF7I,19
|
|
12
|
+
executable_stories_pytest-0.2.0.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
executable_stories/__init__.py,sha256=X-m5x5nt_kkzd8IGJZ52e6lfr6aDArhbXci9K0fLWLM,132
|
|
2
|
-
executable_stories/_collector.py,sha256=gYQKlNTYpcCaNiTDbJXEV4IDWC4T7mF9zxqBz0zx_6k,1508
|
|
3
|
-
executable_stories/_json_writer.py,sha256=FrRuskUN93R-0vVermZTfskv6GZ9Aj6E-khwvmEjnH8,987
|
|
4
|
-
executable_stories/_plugin.py,sha256=_ETuIyO8kkrkTjAbCIhvN8B1h5ljvY_UCJZNAuQNvYM,15912
|
|
5
|
-
executable_stories/_story_api.py,sha256=IGnqjBQiI6C3LaAranVRlNS7K8VXOHwxzuWyF18hoGQ,28021
|
|
6
|
-
executable_stories/_types.py,sha256=Ul2-oobefoxCEV0PLmmUgm1aYgX9rdnAR8HNX4EkwTw,7387
|
|
7
|
-
executable_stories_pytest-0.1.1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
8
|
-
executable_stories_pytest-0.1.1.dist-info/METADATA,sha256=A_ohTC8Byy7-SfCdz7-cTR8zaVTPNeb-vCve6IdxdhU,4546
|
|
9
|
-
executable_stories_pytest-0.1.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
10
|
-
executable_stories_pytest-0.1.1.dist-info/entry_points.txt,sha256=NXzZqAD31EI6q3ovbbWQE7VOzsok09tPpmd-QPgSTiE,59
|
|
11
|
-
executable_stories_pytest-0.1.1.dist-info/top_level.txt,sha256=0CmAUpeJrtl-ykfogdr3L373JMtP92uU1P7-GIlbF7I,19
|
|
12
|
-
executable_stories_pytest-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|