Issue: neotest-python fails to discover deeply nested pytest-describe tests
Summary
neotest-python cannot discover or run pytest-describe tests organized with container functions at arbitrary nesting depths. Tests are marked as not found, and the error message shows only the leaf test function name without the full container hierarchy.
Description
When using pytest-describe with nested container functions (describe, context, when, etc.), neotest-python fails to build the complete test path needed by pytest.
Example Test Structure
def describe_header():
"""Header structure for all ASDUs."""
def context_asdu_address_validation():
"""Validation rules for asdu_address field."""
def when_asdu_address_is_below_minimum():
"""asdu_address < 1 violates the minimum constraint."""
def then_it_raises_asdu_validation_error():
with pytest.raises(AsduValidationError):
Header(
type_id=VALID_TYPE_ID,
cause=VALID_CAUSE,
asdu_address=BELOW_MINIMUM_ASDU_ADDRESS,
)
Error Message
ERROR: not found: /home/.../tests/test_shared.py::then_it_raises_asdu_validation_error
(no match in any of [<Module test_shared.py>])
Expected Behavior
pytest can find and run the test when given the full path:
$ pytest tests/test_shared.py::describe_header::context_asdu_address_validation::when_asdu_address_is_below_minimum::then_it_raises_asdu_validation_error
# Test runs successfully
Actual Behavior
neotest-python only tries to run with the leaf function name, missing all parent container functions.
Root Cause
- Limited treesitter query: neotest-python's treesitter query only recognizes test functions (
test_*, it_*), not container functions
- No describe_prefixes support: The treesitter query doesn't recognize pytest-describe's
describe_prefixes configuration
- Shallow nesting only: The query pattern only handles 2 levels of nesting maximum
Environment
- neotest-python: Latest version
- pytest-describe: 3.1.0+
- nvim-treesitter: Latest
- Python: 3.x
Configuration
pyproject.toml:
[tool.pytest.ini_options]
python_functions = ["test_*", "then_*"]
python_classes = ["Test*", "Describe*", "When*"]
describe_prefixes = ["describe", "context", "when", "given", "scenario", "requirement"]
Steps to Reproduce
- Create a pytest test file with nested pytest-describe container functions (3+ levels)
- Open in Neovim with neotest and neotest-python
- Try to run a nested test function
- Observe "not found" error
Solution Proposal
The treesitter query generation should:
- Extract
describe_prefixes from pytest configuration
- Generate query rules for container functions (creating namespaces)
- Generate query rules for test functions
- Support unlimited nesting depth
This would allow neotest-python to correctly build the full test path hierarchy that pytest expects.
Related Files
lua/neotest-python/base.lua - Treesitter query generation
neotest_python/pytest.py - pytest configuration extraction
Impact
This affects anyone using pytest-describe with nesting deeper than 1 level. The plugin should support arbitrary nesting depths as pytest-describe itself does.
Issue: neotest-python fails to discover deeply nested pytest-describe tests
Summary
neotest-python cannot discover or run pytest-describe tests organized with container functions at arbitrary nesting depths. Tests are marked as not found, and the error message shows only the leaf test function name without the full container hierarchy.
Description
When using pytest-describe with nested container functions (describe, context, when, etc.), neotest-python fails to build the complete test path needed by pytest.
Example Test Structure
Error Message
Expected Behavior
pytest can find and run the test when given the full path:
$ pytest tests/test_shared.py::describe_header::context_asdu_address_validation::when_asdu_address_is_below_minimum::then_it_raises_asdu_validation_error # Test runs successfullyActual Behavior
neotest-python only tries to run with the leaf function name, missing all parent container functions.
Root Cause
test_*,it_*), not container functionsdescribe_prefixesconfigurationEnvironment
Configuration
pyproject.toml:Steps to Reproduce
Solution Proposal
The treesitter query generation should:
describe_prefixesfrom pytest configurationThis would allow neotest-python to correctly build the full test path hierarchy that pytest expects.
Related Files
lua/neotest-python/base.lua- Treesitter query generationneotest_python/pytest.py- pytest configuration extractionImpact
This affects anyone using pytest-describe with nesting deeper than 1 level. The plugin should support arbitrary nesting depths as pytest-describe itself does.