Skip to content

Conversation

@JayBazuzi
Copy link
Contributor

@JayBazuzi JayBazuzi commented Jan 26, 2026

Closes #114

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 26, 2026

Reviewer's Guide

Adds async equivalents of combination approval helpers and refactors label formatting into a shared helper, along with pytest async integration tests and approved outputs.

Sequence diagram for async combination approvals verification

sequenceDiagram
    actor PytestTest as Pytest_test_async_function
    participant VerifyAsync as verify_all_combinations_async
    participant PrintAsync as print_combinations_async
    participant FuncUT as function_under_test
    participant Verify as verify

    PytestTest->>VerifyAsync: await verify_all_combinations_async(function_under_test, input_arguments, formatter, reporter, options)
    VerifyAsync->>VerifyAsync: options = initialize_options(options, reporter)
    VerifyAsync->>PrintAsync: await print_combinations_async(formatter, function_under_test, product(*input_arguments))
    activate PrintAsync
    loop for each args in parameter_combinations
        PrintAsync->>FuncUT: await function_under_test(*args)
        alt function_under_test raises exception
            FuncUT-->>PrintAsync: exception
            PrintAsync->>PrintAsync: result = exception
        else function_under_test returns normally
            FuncUT-->>PrintAsync: result
        end
        PrintAsync->>PrintAsync: approval_strings.append(formatter(args, result))
    end
    PrintAsync-->>VerifyAsync: text
    deactivate PrintAsync
    VerifyAsync->>Verify: verify(text, options)
    Verify-->>VerifyAsync: None
    VerifyAsync-->>PytestTest: None

    %% Labeled async helper wrapper
    participant VerifyLabeledAsync as verify_all_combinations_with_labeled_input_async
    participant GetLabelFormatter as _get_label_formatter

    PytestTest->>VerifyLabeledAsync: await verify_all_combinations_with_labeled_input_async(function_under_test, **kwargs, options)
    VerifyLabeledAsync->>VerifyLabeledAsync: labels = list(kwargs.keys())
    VerifyLabeledAsync->>VerifyLabeledAsync: input_arguments = [kwargs[key] for key in kwargs]
    VerifyLabeledAsync->>GetLabelFormatter: _get_label_formatter(labels)
    GetLabelFormatter-->>VerifyLabeledAsync: formatter
    VerifyLabeledAsync->>VerifyAsync: await verify_all_combinations_async(function_under_test, input_arguments, formatter, None, options=options)
Loading

Class diagram for combination approvals async helpers and label formatter

classDiagram
    class CombinationApprovalsModule {
        +_get_label_formatter(labels: List~str~) Callable
        +verify_all_combinations_with_labeled_input(function_under_test: Callable, options: Optional~Options~, **kwargs: Any) None
        +args_and_result_formatter(args: List~Any~, result: int) str
        +print_combinations_async(formatter: Optional~Callable~, function_under_test: Callable, parameter_combinations: CombinationsOfParameters) str
        +verify_all_combinations_async(function_under_test: Callable, input_arguments: VariationForEachParameter, formatter: Optional~Callable~, reporter: Optional~ReporterForTesting~, options: Optional~Options~) None
        +verify_all_combinations_with_labeled_input_async(function_under_test: Callable, options: Optional~Options~, **kwargs: Any) None
    }

    class FormatterFunction {
        <<function>>
        +__call__(inputs: Sequence~Any~, output: Any) str
    }

    class AsyncFormatterFunction {
        <<function>>
        +__call__(args: List~Any~, result: Any) str
    }

    class FunctionUnderTestSync {
        <<function>>
        +__call__(*args: Any) Any
    }

    class FunctionUnderTestAsync {
        <<coroutine>>
        +__call__(*args: Any) Any
    }

    class Options {
    }

    class ReporterForTesting {
    }

    class CombinationsOfParameters {
        <<iterator>>
        +__iter__() Iterator~List~Any~~
    }

    class VariationForEachParameter {
        <<iterable>>
    }

    CombinationApprovalsModule ..> FormatterFunction : uses
    CombinationApprovalsModule ..> AsyncFormatterFunction : uses
    CombinationApprovalsModule ..> FunctionUnderTestSync : uses
    CombinationApprovalsModule ..> FunctionUnderTestAsync : uses
    CombinationApprovalsModule ..> Options : uses
    CombinationApprovalsModule ..> ReporterForTesting : uses
    CombinationApprovalsModule ..> CombinationsOfParameters : uses
    CombinationApprovalsModule ..> VariationForEachParameter : uses

    CombinationApprovalsModule "1" o-- "many" FormatterFunction : creates_via__get_label_formatter
    CombinationApprovalsModule "1" ..> "1" AsyncFormatterFunction : default_args_and_result_formatter

    FormatterFunction <|.. AsyncFormatterFunction
    FunctionUnderTestSync <|.. FunctionUnderTestAsync
Loading

File-Level Changes

Change Details Files
Refactor labeled input formatter into a reusable helper for combination approvals.
  • Extract the inline labeled-argument formatter into a private _get_label_formatter(labels) function to centralize label formatting logic.
  • Update verify_all_combinations_with_labeled_input to use the shared _get_label_formatter helper when passing the formatter into verify_all_combinations.
approvaltests/combination_approvals.py
Introduce async APIs for verifying all combinations, including labeled-input support, with consistent formatting and exception capture.
  • Add print_combinations_async to iterate async over parameter combinations, await the function_under_test per combination, capture exceptions as results, and format outputs using either a provided formatter or args_and_result_formatter.
  • Add verify_all_combinations_async to wire async combination printing into the existing verify/options pipeline, including reporter initialization.
  • Add verify_all_combinations_with_labeled_input_async to provide labeled-input async verification using the shared _get_label_formatter helper.
approvaltests/combination_approvals.py
Add pytest async integration tests and approved files for the new async combination verification behavior.
  • Extend async integration tests to cover basic async combination verification, labeled-input async combinations, and exception recording behavior using the new async helpers.
  • Import the new async verification functions in the pytest async integration test module.
  • Add approved text files for the new async combination tests to lock in the current output format.
tests/integrations/pytest/test_async_functions.py
tests/integrations/pytest/test_async_functions.test_async_combination_records_exceptions.approved.txt
tests/integrations/pytest/test_async_functions.test_async_verify_all_combinations.approved.txt
tests/integrations/pytest/test_async_functions.test_async_verify_all_combinations_with_labeled_input.approved.txt

Assessment against linked issues

Issue Objective Addressed Explanation
#114 ApprovalTests should work within pytest async tests (e.g., using pytest-asyncio) so that calling verify() inside an async test function does not fail with a StackFrameNamer / AttributeError.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for async tests?

2 participants