Skip to content

Review Missing Python Tests

Automatically request changes for Python PRs that lack test files.

Review Missing Python Tests

Configuration Description

Conditions (all must be true):

  • The PR creates one or more new Python files
  • The PR lacks new test files that match the name of the Python files

Automation Actions:

  • Apply a red missing-tests label
  • Request changes and post a comment listing the files that need tests.

Review Missing Python Tests

# -*- mode: yaml -*-
manifest:
  version: 1.0

newFiles: {{ source.diff.files | filter(attr='new_file', regex=r/^src\/(?!test_.*\.py$).*\.py$/) | filter(attr='original_file', regex=r/^$/) | map(attr='new_file') }}
newTests: {{ source.diff.files | filter(attr='new_file', regex=r/^tests\/test_.*\.py$/) | filter(attr='original_file', regex=r/^$/) | map(attr='new_file') }}

newFilesCount: {{ source.diff.files | filter(attr='new_file', regex=r/^src\/(?!test_.*\.py$).*\.py$/) | filter(attr='original_file', regex=r/^$/) | length }}
newTestsCount: {{ source.diff.files | filter(attr='new_file', regex=r/^tests\/test_.*\.py$/) | filter(attr='original_file', regex=r/^$/) | length }}

automations:
  review_missing_python_tests:
    if:
      - {{ newFilesCount != newTestsCount }}
    run: 
      - action: add-label@v1
        args:
            label: "⚠️ Missing Tests"
            color: {{ colors.orange }}    
      - action: request-changes@v1
        args:
          comment: |
            Some of your new Python files are missing corresponding tests. Please ensure that all new files have a corresponding test file.

            **New Files**: {{ newFilesCount }}
            {{ newFiles }}

            **New Tests**: {{ newTestsCount }}
            {{ newTests }}
colors:
  orange: 'd93f0b'