Skip to content

Fix async test function detection in project inspector #32

@Fieldnote-Echo

Description

Problem

The project inspector in src/navi_bootstrap/init.py (line 252) counts test functions using:

count += len(re.findall(r"^\s*def test_", content, re.MULTILINE))

This misses async def test_* functions, undercounting the test suite for projects that use async tests (e.g. with pytest-asyncio).

Fix

Update the regex to match both sync and async test functions:

count += len(re.findall(r"^\s*(?:async\s+)?def test_", content, re.MULTILINE))

Tests

Add a test that creates a temporary file containing both sync and async test functions and verifies the count includes both:

def test_detect_async_tests(tmp_path):
    test_file = tmp_path / "tests" / "test_example.py"
    test_file.parent.mkdir()
    test_file.write_text(
        "def test_sync(): pass\n"
        "async def test_async(): pass\n"
    )
    info = detect_test_info(tmp_path)
    assert info["test_count"] == 2

Files to change

  • src/navi_bootstrap/init.py (line 252)
  • tests/test_init.py

Ref

DEBT.md item D1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions