pytest-big-dill 0.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.
- pytest_big_dill-0.1.0/.gitignore +30 -0
- pytest_big_dill-0.1.0/LICENSE +21 -0
- pytest_big_dill-0.1.0/PKG-INFO +119 -0
- pytest_big_dill-0.1.0/README.md +98 -0
- pytest_big_dill-0.1.0/developer-guide.md +187 -0
- pytest_big_dill-0.1.0/pyproject.toml +55 -0
- pytest_big_dill-0.1.0/pytest_big_dill/__init__.py +4 -0
- pytest_big_dill-0.1.0/pytest_big_dill/__main__.py +43 -0
- pytest_big_dill-0.1.0/pytest_big_dill/bridge.py +254 -0
- pytest_big_dill-0.1.0/pytest_big_dill/docstring_utils.py +57 -0
- pytest_big_dill-0.1.0/pytest_big_dill/hooks.py +340 -0
- pytest_big_dill-0.1.0/pytest_big_dill/hookspec.py +110 -0
- pytest_big_dill-0.1.0/pytest_big_dill/lint_runner.py +87 -0
- pytest_big_dill-0.1.0/pytest_big_dill/lint_types.py +45 -0
- pytest_big_dill-0.1.0/pytest_big_dill/metadata_gen.py +67 -0
- pytest_big_dill-0.1.0/pytest_big_dill/step_registry.py +182 -0
- pytest_big_dill-0.1.0/pytest_big_dill/step_types.py +50 -0
- pytest_big_dill-0.1.0/tests/conftest.py +15 -0
- pytest_big_dill-0.1.0/tests/test_bdd_lint_option.py +100 -0
- pytest_big_dill-0.1.0/tests/test_bridge.py +268 -0
- pytest_big_dill-0.1.0/tests/test_custom_status.py +131 -0
- pytest_big_dill-0.1.0/tests/test_docstring_transformer_hook.py +136 -0
- pytest_big_dill-0.1.0/tests/test_docstring_utils.py +72 -0
- pytest_big_dill-0.1.0/tests/test_gutter_lineno.py +155 -0
- pytest_big_dill-0.1.0/tests/test_lint_runner.py +102 -0
- pytest_big_dill-0.1.0/tests/test_lint_types.py +41 -0
- pytest_big_dill-0.1.0/tests/test_metadata_gen_steps.py +113 -0
- pytest_big_dill-0.1.0/tests/test_scenario_outline.py +216 -0
- pytest_big_dill-0.1.0/tests/test_step_registry_enriched.py +113 -0
- pytest_big_dill-0.1.0/tests/test_step_types.py +54 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Node
|
|
2
|
+
node_modules/
|
|
3
|
+
dist/
|
|
4
|
+
out/
|
|
5
|
+
*.tsbuildinfo
|
|
6
|
+
*.vsix
|
|
7
|
+
.vscode-test/
|
|
8
|
+
coverage/
|
|
9
|
+
|
|
10
|
+
# Python
|
|
11
|
+
__pycache__/
|
|
12
|
+
*.py[cod]
|
|
13
|
+
*.egg-info/
|
|
14
|
+
.eggs/
|
|
15
|
+
dist/
|
|
16
|
+
build/
|
|
17
|
+
.venv/
|
|
18
|
+
venv/
|
|
19
|
+
.pytest_cache/
|
|
20
|
+
.mypy_cache/
|
|
21
|
+
htmlcov/
|
|
22
|
+
.coverage
|
|
23
|
+
|
|
24
|
+
# OS
|
|
25
|
+
.DS_Store
|
|
26
|
+
Thumbs.db
|
|
27
|
+
|
|
28
|
+
# Git worktrees
|
|
29
|
+
.worktrees/
|
|
30
|
+
**/.claude
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nigel O'Keefe
|
|
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.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pytest-big-dill
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: pytest plugin for the Big Dill test runner
|
|
5
|
+
Project-URL: Homepage, https://github.com/nokout/big-dill
|
|
6
|
+
Project-URL: Repository, https://github.com/nokout/big-dill
|
|
7
|
+
Project-URL: Issues, https://github.com/nokout/big-dill/issues
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: bdd,cucumber,gherkin,pytest,pytest-bdd,vscode
|
|
11
|
+
Classifier: Framework :: Pytest
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
|
+
Classifier: Topic :: Software Development :: Testing :: BDD
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Requires-Dist: parse>=1.19
|
|
18
|
+
Requires-Dist: pytest-bdd>=6
|
|
19
|
+
Requires-Dist: pytest>=7
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# pytest-big-dill
|
|
23
|
+
|
|
24
|
+
The pytest plugin for [Big Dill](https://github.com/nokout/big-dill) — tooling for
|
|
25
|
+
[pytest-bdd](https://pytest-bdd.readthedocs.io/) that treats the feature file as
|
|
26
|
+
the specification.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install pytest-big-dill
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
It registers with pytest automatically. Install it into the environment your
|
|
33
|
+
tests run in.
|
|
34
|
+
|
|
35
|
+
## What it does
|
|
36
|
+
|
|
37
|
+
- **Feature metadata** — attaches the `.feature` path, scenario name, tags and
|
|
38
|
+
scenario line to each collected pytest-bdd item, so a host can present tests
|
|
39
|
+
grouped by feature file rather than by Python module.
|
|
40
|
+
- **Custom scenario names** — name outline rows something meaningful (`[E01]`)
|
|
41
|
+
rather than a concatenation of parameter values.
|
|
42
|
+
- **Custom statuses** — report your own outcome strings (`waiting`,
|
|
43
|
+
`knownError`) for a host to map onto its own test states.
|
|
44
|
+
- **Linting** — `pytest --bdd-lint` statically checks feature files: typed step
|
|
45
|
+
parameter validation, plus any rules you add.
|
|
46
|
+
- **Reporting** — sends discovery and execution payloads to a host over a local
|
|
47
|
+
pipe when one is listening, and is inert otherwise.
|
|
48
|
+
|
|
49
|
+
## Where this fits
|
|
50
|
+
|
|
51
|
+
| | |
|
|
52
|
+
|---|---|
|
|
53
|
+
| **`pytest-big-dill`** | this package — required; it is what knows about your scenarios |
|
|
54
|
+
| [`big-dill`](https://marketplace.visualstudio.com/items?itemName=nokout.big-dill) | the VS Code extension |
|
|
55
|
+
| [`@nokout/big-dill-core`](https://www.npmjs.com/package/@nokout/big-dill-core) | the headless engine the extension is built on |
|
|
56
|
+
|
|
57
|
+
Useful on its own as a CI lint gate; the editor experience needs the extension
|
|
58
|
+
too.
|
|
59
|
+
|
|
60
|
+
## Hooks
|
|
61
|
+
|
|
62
|
+
Implement any of these in your `conftest.py`:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
def pytest_big_dill_test_name(scenario_name, example_params, feature_name, feature_path):
|
|
66
|
+
"""A display name for a scenario, or None to keep the default."""
|
|
67
|
+
if example_params.get("id"):
|
|
68
|
+
return f"{scenario_name} [{example_params['id']}]"
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def pytest_big_dill_custom_status(report, config):
|
|
73
|
+
"""A custom status string for a result, or None."""
|
|
74
|
+
if getattr(report, "wasxfail", None):
|
|
75
|
+
return "knownError"
|
|
76
|
+
return None
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Two more add your own lint rules, each returning a list of `LintDiagnostic`:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from pytest_big_dill.lint_types import LintDiagnostic
|
|
83
|
+
|
|
84
|
+
def pytest_big_dill_lint_outline(scenario, examples):
|
|
85
|
+
"""Once per Scenario Outline during --bdd-lint."""
|
|
86
|
+
|
|
87
|
+
def pytest_big_dill_lint_scenario(scenario):
|
|
88
|
+
"""Per scenario, and per interpolated Examples row."""
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Full reference, including typed step parameters:
|
|
92
|
+
[developer guide](https://github.com/nokout/big-dill/blob/main/pytest-plugin/developer-guide.md).
|
|
93
|
+
|
|
94
|
+
## Linting
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pytest --bdd-lint # every discovered feature file
|
|
98
|
+
pytest --bdd-lint path.feature
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Exits non-zero on any error-severity diagnostic, so it works as a CI gate.
|
|
102
|
+
|
|
103
|
+
This package contributes the runtime half of the lint story: typed step parameter
|
|
104
|
+
validation, undefined-step detection, and whatever your own hooks add. Structural
|
|
105
|
+
rules about the Gherkin itself — duplicate scenario names, unused Examples
|
|
106
|
+
columns, outlines with a single row — come from the engine and are listed with
|
|
107
|
+
everything else in the
|
|
108
|
+
[lint rules reference](https://github.com/nokout/big-dill/blob/main/docs/lint-rules.md).
|
|
109
|
+
|
|
110
|
+
## Documentation
|
|
111
|
+
|
|
112
|
+
- [Developer guide](https://github.com/nokout/big-dill/blob/main/pytest-plugin/developer-guide.md) — hookspecs, typed steps, custom lint rules
|
|
113
|
+
- [Lint rules](https://github.com/nokout/big-dill/blob/main/docs/lint-rules.md) — every diagnostic, across all three packages
|
|
114
|
+
- [Repository](https://github.com/nokout/big-dill)
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
MIT. See [`LICENSE`](https://github.com/nokout/big-dill/blob/main/LICENSE) and
|
|
119
|
+
[`THIRD-PARTY-NOTICES.md`](https://github.com/nokout/big-dill/blob/main/THIRD-PARTY-NOTICES.md).
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# pytest-big-dill
|
|
2
|
+
|
|
3
|
+
The pytest plugin for [Big Dill](https://github.com/nokout/big-dill) — tooling for
|
|
4
|
+
[pytest-bdd](https://pytest-bdd.readthedocs.io/) that treats the feature file as
|
|
5
|
+
the specification.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install pytest-big-dill
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
It registers with pytest automatically. Install it into the environment your
|
|
12
|
+
tests run in.
|
|
13
|
+
|
|
14
|
+
## What it does
|
|
15
|
+
|
|
16
|
+
- **Feature metadata** — attaches the `.feature` path, scenario name, tags and
|
|
17
|
+
scenario line to each collected pytest-bdd item, so a host can present tests
|
|
18
|
+
grouped by feature file rather than by Python module.
|
|
19
|
+
- **Custom scenario names** — name outline rows something meaningful (`[E01]`)
|
|
20
|
+
rather than a concatenation of parameter values.
|
|
21
|
+
- **Custom statuses** — report your own outcome strings (`waiting`,
|
|
22
|
+
`knownError`) for a host to map onto its own test states.
|
|
23
|
+
- **Linting** — `pytest --bdd-lint` statically checks feature files: typed step
|
|
24
|
+
parameter validation, plus any rules you add.
|
|
25
|
+
- **Reporting** — sends discovery and execution payloads to a host over a local
|
|
26
|
+
pipe when one is listening, and is inert otherwise.
|
|
27
|
+
|
|
28
|
+
## Where this fits
|
|
29
|
+
|
|
30
|
+
| | |
|
|
31
|
+
|---|---|
|
|
32
|
+
| **`pytest-big-dill`** | this package — required; it is what knows about your scenarios |
|
|
33
|
+
| [`big-dill`](https://marketplace.visualstudio.com/items?itemName=nokout.big-dill) | the VS Code extension |
|
|
34
|
+
| [`@nokout/big-dill-core`](https://www.npmjs.com/package/@nokout/big-dill-core) | the headless engine the extension is built on |
|
|
35
|
+
|
|
36
|
+
Useful on its own as a CI lint gate; the editor experience needs the extension
|
|
37
|
+
too.
|
|
38
|
+
|
|
39
|
+
## Hooks
|
|
40
|
+
|
|
41
|
+
Implement any of these in your `conftest.py`:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
def pytest_big_dill_test_name(scenario_name, example_params, feature_name, feature_path):
|
|
45
|
+
"""A display name for a scenario, or None to keep the default."""
|
|
46
|
+
if example_params.get("id"):
|
|
47
|
+
return f"{scenario_name} [{example_params['id']}]"
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def pytest_big_dill_custom_status(report, config):
|
|
52
|
+
"""A custom status string for a result, or None."""
|
|
53
|
+
if getattr(report, "wasxfail", None):
|
|
54
|
+
return "knownError"
|
|
55
|
+
return None
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Two more add your own lint rules, each returning a list of `LintDiagnostic`:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from pytest_big_dill.lint_types import LintDiagnostic
|
|
62
|
+
|
|
63
|
+
def pytest_big_dill_lint_outline(scenario, examples):
|
|
64
|
+
"""Once per Scenario Outline during --bdd-lint."""
|
|
65
|
+
|
|
66
|
+
def pytest_big_dill_lint_scenario(scenario):
|
|
67
|
+
"""Per scenario, and per interpolated Examples row."""
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Full reference, including typed step parameters:
|
|
71
|
+
[developer guide](https://github.com/nokout/big-dill/blob/main/pytest-plugin/developer-guide.md).
|
|
72
|
+
|
|
73
|
+
## Linting
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pytest --bdd-lint # every discovered feature file
|
|
77
|
+
pytest --bdd-lint path.feature
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Exits non-zero on any error-severity diagnostic, so it works as a CI gate.
|
|
81
|
+
|
|
82
|
+
This package contributes the runtime half of the lint story: typed step parameter
|
|
83
|
+
validation, undefined-step detection, and whatever your own hooks add. Structural
|
|
84
|
+
rules about the Gherkin itself — duplicate scenario names, unused Examples
|
|
85
|
+
columns, outlines with a single row — come from the engine and are listed with
|
|
86
|
+
everything else in the
|
|
87
|
+
[lint rules reference](https://github.com/nokout/big-dill/blob/main/docs/lint-rules.md).
|
|
88
|
+
|
|
89
|
+
## Documentation
|
|
90
|
+
|
|
91
|
+
- [Developer guide](https://github.com/nokout/big-dill/blob/main/pytest-plugin/developer-guide.md) — hookspecs, typed steps, custom lint rules
|
|
92
|
+
- [Lint rules](https://github.com/nokout/big-dill/blob/main/docs/lint-rules.md) — every diagnostic, across all three packages
|
|
93
|
+
- [Repository](https://github.com/nokout/big-dill)
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT. See [`LICENSE`](https://github.com/nokout/big-dill/blob/main/LICENSE) and
|
|
98
|
+
[`THIRD-PARTY-NOTICES.md`](https://github.com/nokout/big-dill/blob/main/THIRD-PARTY-NOTICES.md).
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Developer Guide
|
|
2
|
+
|
|
3
|
+
This guide covers implementing step definitions, typed parameters, and custom hooks for Big Dill.
|
|
4
|
+
|
|
5
|
+
## Step definitions
|
|
6
|
+
|
|
7
|
+
Steps are standard pytest-bdd decorated functions in your `conftest.py` or step definition files. The extension discovers them automatically.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from pytest_bdd import given, when, then, parsers
|
|
11
|
+
|
|
12
|
+
@given("the user is logged in")
|
|
13
|
+
def user_logged_in():
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
@when(parsers.parse("the user navigates to {page}"))
|
|
17
|
+
def user_navigates(page: str):
|
|
18
|
+
pass
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Typed parameters with StepEnum
|
|
22
|
+
|
|
23
|
+
`StepEnum` lets you define a closed set of valid values for a step parameter. The extension uses this to:
|
|
24
|
+
|
|
25
|
+
- Show a pick-list in step completions
|
|
26
|
+
- Warn in the linter when an invalid value is used
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from pytest_big_dill import StepEnum
|
|
30
|
+
|
|
31
|
+
class AustralianState(StepEnum):
|
|
32
|
+
NSW = "New South Wales"
|
|
33
|
+
VIC = "Victoria"
|
|
34
|
+
QLD = "Queensland"
|
|
35
|
+
|
|
36
|
+
@given(parsers.cfparse(
|
|
37
|
+
"the capital of {state:AustralianState} is visited",
|
|
38
|
+
extra_types={"AustralianState": AustralianState},
|
|
39
|
+
))
|
|
40
|
+
def visit_capital(state: AustralianState):
|
|
41
|
+
...
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The enum values (left-hand side: `NSW`, `VIC`) are what testers type in `.feature` files. The display names (right-hand side: `"New South Wales"`) are shown in hover docs.
|
|
45
|
+
|
|
46
|
+
## Hookspecs
|
|
47
|
+
|
|
48
|
+
Add these functions to your `conftest.py` to customise extension behaviour.
|
|
49
|
+
|
|
50
|
+
### `pytest_big_dill_test_name`
|
|
51
|
+
|
|
52
|
+
Override the display name for scenarios, particularly outline rows:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
def pytest_big_dill_test_name(scenario_name, example_params, feature_name, feature_path):
|
|
56
|
+
if not example_params:
|
|
57
|
+
return scenario_name
|
|
58
|
+
if "id" in example_params:
|
|
59
|
+
return f"{scenario_name} [{example_params['id']}]"
|
|
60
|
+
return f"{scenario_name} [{', '.join(str(v) for v in example_params.values())}]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Parameters:
|
|
64
|
+
- `scenario_name` — the Gherkin `Scenario:` name
|
|
65
|
+
- `example_params` — dict of column name → value for the current outline row (empty for non-outline scenarios)
|
|
66
|
+
- `feature_name` — the `Feature:` name
|
|
67
|
+
- `feature_path` — absolute path to the `.feature` file
|
|
68
|
+
|
|
69
|
+
Return `None` to keep the default name.
|
|
70
|
+
|
|
71
|
+
### `pytest_big_dill_custom_status`
|
|
72
|
+
|
|
73
|
+
Map sentinel exceptions to custom status strings:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
def pytest_big_dill_custom_status(report, config):
|
|
77
|
+
if report.when != "call":
|
|
78
|
+
return None
|
|
79
|
+
longrepr = str(getattr(report, "longrepr", ""))
|
|
80
|
+
if "WaitingSignal" in longrepr:
|
|
81
|
+
return "waiting"
|
|
82
|
+
if "KnownError" in longrepr:
|
|
83
|
+
return "knownError"
|
|
84
|
+
return None
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The returned string is matched against `big-dill.outcomeMapping` in workspace settings to determine the VS Code run state. See the [extension settings](https://github.com/nokout/big-dill/blob/main/extension/README.md#settings) for valid run states.
|
|
88
|
+
|
|
89
|
+
### `pytest_big_dill_lint_outline`
|
|
90
|
+
|
|
91
|
+
Add a custom lint rule for Scenario Outlines. Called once per outline during `--bdd-lint`:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from pytest_big_dill.lint_types import LintDiagnostic
|
|
95
|
+
|
|
96
|
+
def pytest_big_dill_lint_outline(scenario, examples):
|
|
97
|
+
if scenario.name and not scenario.name[0].isupper():
|
|
98
|
+
return [LintDiagnostic(
|
|
99
|
+
message=f"Scenario Outline name must start with a capital letter: '{scenario.name}'",
|
|
100
|
+
severity="warning", # "error" | "warning" | "information" | "hint"
|
|
101
|
+
)]
|
|
102
|
+
return []
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`LintDiagnostic` fields:
|
|
106
|
+
- `message` — displayed in the Problems panel
|
|
107
|
+
- `severity` — one of `"error"`, `"warning"`, `"information"`, `"hint"`
|
|
108
|
+
|
|
109
|
+
## Running the linter
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pytest --bdd-lint
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This runs the built-in structural rules plus any `pytest_big_dill_lint_outline` hooks from your `conftest.py`. It does not run tests — it is a static analysis pass only.
|
|
116
|
+
|
|
117
|
+
## Docstring parameters
|
|
118
|
+
|
|
119
|
+
Step functions can receive the content of a Gherkin docstring block by declaring a `docstring` parameter:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import json
|
|
123
|
+
import yaml
|
|
124
|
+
|
|
125
|
+
@given("the service is configured with the following JSON:")
|
|
126
|
+
def service_configured(docstring):
|
|
127
|
+
config = json.loads(docstring)
|
|
128
|
+
|
|
129
|
+
@given("the pipeline is seeded with the following YAML:")
|
|
130
|
+
def pipeline_seeded(docstring):
|
|
131
|
+
data = yaml.safe_load(docstring)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The `docstring` parameter name is detected by pytest-bdd automatically — no imports required.
|
|
135
|
+
|
|
136
|
+
## Datatable parameters
|
|
137
|
+
|
|
138
|
+
Step functions receive datatable data by declaring a `datatable` parameter:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
@given("the following users exist")
|
|
142
|
+
def users_exist(datatable):
|
|
143
|
+
# datatable is a list of lists; first row is typically headers
|
|
144
|
+
headers, *rows = datatable
|
|
145
|
+
users = [dict(zip(headers, row)) for row in rows]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Metadata for the step browser
|
|
149
|
+
|
|
150
|
+
The step browser shows hover docs and tags sourced from your step function's docstring. Use Google-style format:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
@given(parsers.parse("the user selects {state} from the dropdown"))
|
|
154
|
+
def select_state(state: str):
|
|
155
|
+
"""Select a value from the state dropdown widget.
|
|
156
|
+
|
|
157
|
+
Tags:
|
|
158
|
+
ui, geography
|
|
159
|
+
"""
|
|
160
|
+
...
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The first line becomes the summary shown on hover. Lines under `Tags:` become the step's tags in the browser.
|
|
164
|
+
|
|
165
|
+
## Shipping steps in a package
|
|
166
|
+
|
|
167
|
+
If you publish a package of reusable step definitions, consumers get completions for your
|
|
168
|
+
steps as soon as they install it — but only after a discovery run has collected them. To
|
|
169
|
+
give them completions immediately, ship a metadata file alongside your code.
|
|
170
|
+
|
|
171
|
+
Generate it at packaging time:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pytest-big-dill # writes pytest_big_dill_steps.json
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Include that file in your wheel and declare it with an entry point:
|
|
178
|
+
|
|
179
|
+
```toml
|
|
180
|
+
[project.entry-points."pytest_big_dill.steps"]
|
|
181
|
+
my-package = "my_package:pytest_big_dill_steps.json"
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
On activation the extension enumerates every registered `pytest_big_dill.steps` entry
|
|
185
|
+
point and loads the metadata as a base layer. Live discovery is merged over the top, and
|
|
186
|
+
local step definitions always take precedence for the same pattern — so a consumer who
|
|
187
|
+
overrides one of your steps sees their own version, not yours.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pytest-big-dill"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "pytest plugin for the Big Dill test runner"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
keywords = ["pytest", "pytest-bdd", "bdd", "gherkin", "cucumber", "vscode"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Framework :: Pytest",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Software Development :: Testing",
|
|
19
|
+
"Topic :: Software Development :: Testing :: BDD",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
dependencies = [
|
|
23
|
+
"pytest>=7",
|
|
24
|
+
"pytest-bdd>=6",
|
|
25
|
+
# lint_runner imports `parse` directly; it currently arrives transitively via
|
|
26
|
+
# pytest-bdd, but that is not a guarantee we should rely on.
|
|
27
|
+
"parse>=1.19",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/nokout/big-dill"
|
|
32
|
+
Repository = "https://github.com/nokout/big-dill"
|
|
33
|
+
Issues = "https://github.com/nokout/big-dill/issues"
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
pytest-big-dill = "pytest_big_dill.metadata_gen:main"
|
|
37
|
+
|
|
38
|
+
[project.entry-points.pytest11]
|
|
39
|
+
pytest-big-dill = "pytest_big_dill.hooks"
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
addopts = "-p pytester"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
packages = ["pytest_big_dill"]
|
|
46
|
+
|
|
47
|
+
[tool.ruff]
|
|
48
|
+
line-length = 100
|
|
49
|
+
target-version = "py310"
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint]
|
|
52
|
+
select = ["E", "F", "W", "I", "UP", "B"]
|
|
53
|
+
ignore = [
|
|
54
|
+
"E501", # line length is handled by the formatter, not enforced as an error
|
|
55
|
+
]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Run pytest for a specific set of tests, read from a file.
|
|
2
|
+
|
|
3
|
+
python -m pytest_big_dill [pytest args...]
|
|
4
|
+
|
|
5
|
+
Test node ids come from the file named by ``BIG_DILL_TEST_IDS`` rather than the
|
|
6
|
+
command line, because Windows caps a command line at roughly 32,000 characters —
|
|
7
|
+
a few hundred BDD scenarios is enough to exceed it, and the failure mode is an
|
|
8
|
+
opaque OS error rather than anything actionable.
|
|
9
|
+
|
|
10
|
+
Without that variable this is simply ``pytest``, so the module is usable by hand.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
|
|
20
|
+
TEST_IDS_ENV = "BIG_DILL_TEST_IDS"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def read_test_ids(path: str) -> list[str]:
|
|
24
|
+
with open(path, encoding="utf-8") as handle:
|
|
25
|
+
return [line.strip() for line in handle if line.strip()]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def main(argv: list[str] | None = None) -> int:
|
|
29
|
+
args = list(argv if argv is not None else sys.argv[1:])
|
|
30
|
+
|
|
31
|
+
ids_file = os.environ.get(TEST_IDS_ENV)
|
|
32
|
+
if ids_file:
|
|
33
|
+
try:
|
|
34
|
+
args.extend(read_test_ids(ids_file))
|
|
35
|
+
except OSError as error:
|
|
36
|
+
print(f"big-dill: cannot read test ids from {ids_file}: {error}", file=sys.stderr)
|
|
37
|
+
return 2
|
|
38
|
+
|
|
39
|
+
return pytest.main(args)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
sys.exit(main())
|