pytest-agent-bdd 0.1.0.dev1__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.
- pytest_agent_bdd/__init__.py +45 -0
- pytest_agent_bdd/adapters.py +98 -0
- pytest_agent_bdd/assertions.py +78 -0
- pytest_agent_bdd/integrations/__init__.py +57 -0
- pytest_agent_bdd/integrations/_dependencies.py +22 -0
- pytest_agent_bdd/integrations/langgraph.py +63 -0
- pytest_agent_bdd/judges/__init__.py +93 -0
- pytest_agent_bdd/models.py +90 -0
- pytest_agent_bdd/plugin.py +160 -0
- pytest_agent_bdd/steps.py +192 -0
- pytest_agent_bdd/validation/__init__.py +169 -0
- pytest_agent_bdd/validation/metrics.py +68 -0
- pytest_agent_bdd/validation/robustness.py +95 -0
- pytest_agent_bdd-0.1.0.dev1.dist-info/METADATA +256 -0
- pytest_agent_bdd-0.1.0.dev1.dist-info/RECORD +18 -0
- pytest_agent_bdd-0.1.0.dev1.dist-info/WHEEL +4 -0
- pytest_agent_bdd-0.1.0.dev1.dist-info/entry_points.txt +3 -0
- pytest_agent_bdd-0.1.0.dev1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pytest-agent-bdd
|
|
3
|
+
Version: 0.1.0.dev1
|
|
4
|
+
Summary: Behavioral acceptance testing for AI agents with Gherkin and pytest-bdd.
|
|
5
|
+
Project-URL: Homepage, https://github.com/bernard357/pytest-agent-bdd
|
|
6
|
+
Project-URL: Repository, https://github.com/bernard357/pytest-agent-bdd
|
|
7
|
+
Project-URL: Issues, https://github.com/bernard357/pytest-agent-bdd/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/bernard357/pytest-agent-bdd/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Bernard Paques
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: acceptance-testing,ai-agents,bdd,gherkin,llm,llm-as-a-judge,pytest,pytest-bdd
|
|
13
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
14
|
+
Classifier: Framework :: Pytest
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Software Development :: Testing :: BDD
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: pytest-bdd>=7
|
|
21
|
+
Requires-Dist: pytest>=8
|
|
22
|
+
Provides-Extra: crewai
|
|
23
|
+
Requires-Dist: crewai>=0.80; extra == 'crewai'
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: hatch>=1.12; extra == 'dev'
|
|
26
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
28
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
29
|
+
Provides-Extra: langgraph
|
|
30
|
+
Requires-Dist: langgraph>=0.2; extra == 'langgraph'
|
|
31
|
+
Provides-Extra: openai-agents
|
|
32
|
+
Requires-Dist: openai-agents>=0.1; extra == 'openai-agents'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# pytest-agent-bdd
|
|
36
|
+
|
|
37
|
+
**Test your AI agents like you test your software.**
|
|
38
|
+
|
|
39
|
+
Write behavioral acceptance tests for AI agents using Gherkin and pytest. Test outputs, tool
|
|
40
|
+
calls, execution traces and custom evaluation criteria — and validate the judges you rely on.
|
|
41
|
+
|
|
42
|
+
```gherkin
|
|
43
|
+
Feature: Customer support agent handles refunds
|
|
44
|
+
|
|
45
|
+
Scenario: Process an authorized refund
|
|
46
|
+
Given the agent input field "confirmed" is "yes"
|
|
47
|
+
When I ask "Please refund order ORD-123"
|
|
48
|
+
Then the agent should invoke the "process_refund" tool
|
|
49
|
+
And the "process_refund" tool should be called with "amount" equal to "100"
|
|
50
|
+
And the "check_refund_eligibility" tool should be invoked before the "process_refund" tool
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
> Status: pre-alpha (0.1.0.dev1). The API is being designed in the open — see
|
|
54
|
+
> [docs/roadmap.md](https://github.com/bernard357/pytest-agent-bdd/blob/main/docs/roadmap.md).
|
|
55
|
+
|
|
56
|
+
## The problem
|
|
57
|
+
|
|
58
|
+
Testing agentic AI systems is fundamentally different from testing conventional software.
|
|
59
|
+
|
|
60
|
+
AI agents exhibit probabilistic and non-deterministic behavior, dynamically interact with
|
|
61
|
+
external tools and services, maintain state, and make decisions across multiple execution
|
|
62
|
+
steps. Validating their final responses alone is insufficient to establish that they behave
|
|
63
|
+
correctly, reliably and safely.
|
|
64
|
+
|
|
65
|
+
Existing tools address LLM evaluation, observability and benchmarking, but engineering teams
|
|
66
|
+
lack a simple, standard way to express and automate **behavioral acceptance tests** for AI
|
|
67
|
+
agents within their existing testing workflows. Agent testing ends up in ad hoc scripts,
|
|
68
|
+
isolated datasets and hand-written assertions that are hard to maintain, reproduce and run in
|
|
69
|
+
CI/CD.
|
|
70
|
+
|
|
71
|
+
pytest-agent-bdd makes agentic systems testable with established engineering practice:
|
|
72
|
+
Gherkin as the behavioral contract, pytest fixtures as dependency injection, and a small
|
|
73
|
+
adapter as the only boundary with your agent framework.
|
|
74
|
+
|
|
75
|
+
> How can we establish that an AI agent behaves correctly, not just that it produces a
|
|
76
|
+
> plausible answer?
|
|
77
|
+
|
|
78
|
+
Full statement: [docs/problem-statement.md](https://github.com/bernard357/pytest-agent-bdd/blob/main/docs/problem-statement.md).
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install pytest-agent-bdd # core, no framework dependency
|
|
84
|
+
pip install "pytest-agent-bdd[langgraph]" # + LangGraph integration
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Your first agent acceptance test (no API key needed)
|
|
88
|
+
|
|
89
|
+
1. Wrap your agent. Any Python callable `agent(input, tools)` works; `tools` records tool calls:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
# conftest.py
|
|
93
|
+
import pytest
|
|
94
|
+
from pytest_agent_bdd import CallableAdapter
|
|
95
|
+
from my_app import support_agent
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@pytest.fixture
|
|
99
|
+
def agent():
|
|
100
|
+
return CallableAdapter(support_agent)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
2. Describe the behavior in `features/support.feature`:
|
|
104
|
+
|
|
105
|
+
```gherkin
|
|
106
|
+
Feature: Support agent
|
|
107
|
+
Scenario: Answer a refund policy question
|
|
108
|
+
When I ask "Can I get a refund within 30 days?"
|
|
109
|
+
Then the agent should respond successfully
|
|
110
|
+
And the response should mention "refund"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
3. Bind the features and run:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# test_support.py
|
|
117
|
+
from pytest_bdd import scenarios
|
|
118
|
+
|
|
119
|
+
scenarios("features")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pytest
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
A complete, runnable example lives in [examples/customer-support](https://github.com/bernard357/pytest-agent-bdd/blob/main/examples/customer-support).
|
|
127
|
+
|
|
128
|
+
When an assertion fails, the error shows the expectation, the agent output, the tool calls in
|
|
129
|
+
order and a trace excerpt — no need to inspect Python objects.
|
|
130
|
+
|
|
131
|
+
## Built-in fixtures
|
|
132
|
+
|
|
133
|
+
| Fixture | Purpose |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `agent` | Agent under test — override it in `conftest.py` |
|
|
136
|
+
| `agent_input` | Mutable scenario input filled by Given steps |
|
|
137
|
+
| `agent_execution` | Normalized record of the latest run (`AgentExecution`) |
|
|
138
|
+
| `agent_result` | Final output |
|
|
139
|
+
| `agent_trace` | Execution trajectory |
|
|
140
|
+
| `tool_calls` | Tool invocation records (`ToolCall`) |
|
|
141
|
+
| `agent_state` | Final agent state |
|
|
142
|
+
| `judges` | Named judge registry (optional) |
|
|
143
|
+
| `judge_validation_config` | Thresholds for judge validation (optional) |
|
|
144
|
+
|
|
145
|
+
All are function-scoped: executions, tool calls and state never leak between scenarios.
|
|
146
|
+
Your own When steps should use `target_fixture="agent_execution"`.
|
|
147
|
+
|
|
148
|
+
## Built-in steps
|
|
149
|
+
|
|
150
|
+
```gherkin
|
|
151
|
+
Given the agent input "<text>"
|
|
152
|
+
Given the agent input field "<key>" is "<value>"
|
|
153
|
+
When I ask "<text>"
|
|
154
|
+
When the agent is run
|
|
155
|
+
Then the agent should respond successfully
|
|
156
|
+
Then the response should mention "<text>"
|
|
157
|
+
Then the agent should invoke the "<tool>" tool
|
|
158
|
+
Then the agent should not invoke the "<tool>" tool
|
|
159
|
+
Then the "<tool>" tool should be called with "<arg>" equal to "<value>"
|
|
160
|
+
Then the "<first>" tool should be invoked before the "<second>" tool
|
|
161
|
+
Then no tool call should report an error
|
|
162
|
+
Then the response should pass evaluation by "<judge>" against "<expected>"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The same checks are available in Python: `assert_tool_called`, `assert_tool_not_called`,
|
|
166
|
+
`assert_called_before`, `assert_execution_succeeded`, `assert_no_tool_errors`.
|
|
167
|
+
|
|
168
|
+
## Custom judges
|
|
169
|
+
|
|
170
|
+
A judge is anything with `evaluate(*, input, actual, expected, context=None) -> Judgment` —
|
|
171
|
+
an LLM, a Python function, an external service or a human workflow. Register judges by name:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
@pytest.fixture
|
|
175
|
+
def judges():
|
|
176
|
+
return {"semantic": MySemanticJudge()}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Every judgment is checked against the judge contract (types, score and confidence within
|
|
180
|
+
[0, 1], non-empty reason); a malformed judgment fails loudly instead of passing silently.
|
|
181
|
+
|
|
182
|
+
## Validating judge reliability
|
|
183
|
+
|
|
184
|
+
A judge that returns well-formed judgments is not necessarily a good judge. Measure it against
|
|
185
|
+
**independent, human-labelled** cases (JSONL) before trusting its verdicts:
|
|
186
|
+
|
|
187
|
+
```gherkin
|
|
188
|
+
@judge_validation
|
|
189
|
+
Feature: Judge quality
|
|
190
|
+
Background:
|
|
191
|
+
Given the "semantic" judge is configured
|
|
192
|
+
And the judge validation dataset "factuality" is loaded
|
|
193
|
+
|
|
194
|
+
Scenario: Judge agrees with human labels
|
|
195
|
+
When I validate the judge against the dataset
|
|
196
|
+
Then the judge accuracy should be at least 0.90
|
|
197
|
+
And the judge false positive rate should be below 0.05
|
|
198
|
+
|
|
199
|
+
Scenario: Judge is robust to prompt injection
|
|
200
|
+
When I run the judge robustness tests
|
|
201
|
+
Then the judge should reject manipulated evaluations
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Reports include the confusion matrix, precision, recall, F1, Cohen's kappa, per-category
|
|
205
|
+
results, class-imbalance warnings, the judge version and a content hash of the dataset.
|
|
206
|
+
|
|
207
|
+
## Running subsets
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
pytest -m agent_bdd # agent acceptance tests
|
|
211
|
+
pytest -m judge_validation # judge validation
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Framework integrations
|
|
215
|
+
|
|
216
|
+
The core imports no agent framework. Integrations are pip extras, loaded lazily:
|
|
217
|
+
|
|
218
|
+
```ini
|
|
219
|
+
[pytest]
|
|
220
|
+
agent_integration = langgraph
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
@pytest.fixture
|
|
225
|
+
def agent_under_test():
|
|
226
|
+
return build_my_graph() # the framework object the integration wraps
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Third-party packages can register adapters under the `pytest_agent_bdd.integrations`
|
|
230
|
+
entry-point group. Writing an adapter: implement `run(input) -> AgentExecution`, and report
|
|
231
|
+
agent failures through `status`/`error` rather than raising.
|
|
232
|
+
|
|
233
|
+
| Integration | Status |
|
|
234
|
+
|---|---|
|
|
235
|
+
| Custom Python agent | Built into core |
|
|
236
|
+
| LangGraph | Skeleton (first-party target) |
|
|
237
|
+
| OpenAI Agents SDK | Planned |
|
|
238
|
+
| CrewAI | Open for a community maintainer |
|
|
239
|
+
|
|
240
|
+
## Documentation
|
|
241
|
+
|
|
242
|
+
- [Problem statement](https://github.com/bernard357/pytest-agent-bdd/blob/main/docs/problem-statement.md)
|
|
243
|
+
- [Architecture and design decisions](https://github.com/bernard357/pytest-agent-bdd/blob/main/docs/architecture.md)
|
|
244
|
+
- [Roadmap, sizing and adoption plan](https://github.com/bernard357/pytest-agent-bdd/blob/main/docs/roadmap.md)
|
|
245
|
+
- [Contributor recruitment plan](https://github.com/bernard357/pytest-agent-bdd/blob/main/docs/contributors.md)
|
|
246
|
+
- [Related literature](https://github.com/bernard357/pytest-agent-bdd/blob/main/docs/literature.md)
|
|
247
|
+
- [Origin: the design conversation](https://github.com/bernard357/pytest-agent-bdd/blob/main/docs/conversation/)
|
|
248
|
+
|
|
249
|
+
## Contributing
|
|
250
|
+
|
|
251
|
+
See [CONTRIBUTING.md](https://github.com/bernard357/pytest-agent-bdd/blob/main/CONTRIBUTING.md). Framework adapters and realistic examples are the most
|
|
252
|
+
valuable contributions right now.
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
MIT
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
pytest_agent_bdd/__init__.py,sha256=efOF_BixtylwM4Xb5BiW11-DdeklkFZY4kw8ZQlFp6o,1239
|
|
2
|
+
pytest_agent_bdd/adapters.py,sha256=j-QSnzxapIkHweoDwsIz6qPwamRlQhZu2_gKIC0hZtU,3514
|
|
3
|
+
pytest_agent_bdd/assertions.py,sha256=DS8Ra5QMv8t9Kws8IxhnhxUI561LLdAXg13XQCK-7Jc,3041
|
|
4
|
+
pytest_agent_bdd/models.py,sha256=0AhD9QJ9GacTju6K9Uo3-fPw1lULl4fA3Nqhg3o1Lmw,2908
|
|
5
|
+
pytest_agent_bdd/plugin.py,sha256=3abpC4epV9ifOguuC0wf23AkQwO6jBchXzOTAndakwg,5175
|
|
6
|
+
pytest_agent_bdd/steps.py,sha256=P8UCHQ2Kql5sd4jrU2hZZ1rDZelPUIMHU8HhGGe6zBc,7260
|
|
7
|
+
pytest_agent_bdd/integrations/__init__.py,sha256=xmxxiCbgyZPm33-nUM00LMxeqxu0-YSrv9SuN9R0BFQ,1972
|
|
8
|
+
pytest_agent_bdd/integrations/_dependencies.py,sha256=LsFRAfMKwYvat8xbeg3rD_YDjg4DNoYSCoYExidKoLU,800
|
|
9
|
+
pytest_agent_bdd/integrations/langgraph.py,sha256=JU4h5zc3u5_86J7YYFQh7miMg0S_EvQgXXFmrTSPbMA,2005
|
|
10
|
+
pytest_agent_bdd/judges/__init__.py,sha256=tUMDAUGaS-0VPhnd5-7Pg7nDs2g7d9vjL52eTMjuIU0,3118
|
|
11
|
+
pytest_agent_bdd/validation/__init__.py,sha256=9k-vHEy_9uquO5ts7_11VEbRuH-BYpOS6sfi1kPyQT4,6226
|
|
12
|
+
pytest_agent_bdd/validation/metrics.py,sha256=BlT-vvk2TIM4W-mCHn4EEBUq-3own-G09A2WUHOxFU4,2094
|
|
13
|
+
pytest_agent_bdd/validation/robustness.py,sha256=ltCuz8MIo83vmWkh4GHUoXkXPLhUdg3H2UVh4C8Go0k,2912
|
|
14
|
+
pytest_agent_bdd-0.1.0.dev1.dist-info/METADATA,sha256=1D9XX26LjaDvli9rgOe7AaxziVgw1foObbopNfD81Hk,9532
|
|
15
|
+
pytest_agent_bdd-0.1.0.dev1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
16
|
+
pytest_agent_bdd-0.1.0.dev1.dist-info/entry_points.txt,sha256=Eb4p2USZt_KVY9qVoA58o-hZ4CsRkXq1N2HOdAxCT74,88
|
|
17
|
+
pytest_agent_bdd-0.1.0.dev1.dist-info/licenses/LICENSE,sha256=0iZwNdrLyC_TNQNSkOVkuhzizKDswsBd7Sqa5fS06g0,1071
|
|
18
|
+
pytest_agent_bdd-0.1.0.dev1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bernard Paques
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|