Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f2b7897
adding jobs to skip test cases and check for skipped test cases in th…
shonilbhide Apr 6, 2025
2a829f7
removing hardcoded version
shonilbhide Apr 6, 2025
9e2b62d
removing the part running test cases in chunks
shonilbhide Apr 6, 2025
230f57f
manually installing pytest-json-report
shonilbhide Apr 6, 2025
4bb240e
adding pytest-json-report to tox.ini
shonilbhide Apr 6, 2025
69e3abe
passing test cases as functions
shonilbhide Apr 6, 2025
a2a48ee
modify your test collection command to preserve the full test paths
shonilbhide Apr 6, 2025
2e0c20c
modify the run command to read the file and pass the tests directly:
shonilbhide Apr 6, 2025
1452328
modify the "Run Remaining Test Cases" step to add the -v flag and ens…
shonilbhide Apr 6, 2025
5047fa2
correcting the issue: test names are being passed without their modul…
shonilbhide Apr 6, 2025
70813a1
creating temp test file for running pytest command
shonilbhide Apr 6, 2025
07b3e0b
running in batches
shonilbhide Apr 6, 2025
9f7b64e
Generate properly formatted JSON files for each batch of tests
shonilbhide Apr 6, 2025
dde7450
fixing issues with scripts
shonilbhide Apr 6, 2025
4adee23
fixing naming issues
shonilbhide Apr 6, 2025
d5962b1
debugging for run.sh file
shonilbhide Apr 6, 2025
3046cfa
typos
shonilbhide Apr 6, 2025
6353d88
debugging
shonilbhide Apr 6, 2025
ab3c5a5
improving grep regex
shonilbhide Apr 6, 2025
88df6a2
fixing generate test script bugs
shonilbhide Apr 6, 2025
a6e10e9
changing grep command
shonilbhide Apr 7, 2025
6b3bafd
fixing bugs
shonilbhide Apr 7, 2025
0898697
fixing duplicate pytest
shonilbhide Apr 7, 2025
5959215
fixing commands
shonilbhide Apr 7, 2025
597e12e
excluding soecial characters from test identifiers
shonilbhide Apr 7, 2025
25c920a
fixing grep issues
shonilbhide Apr 7, 2025
3490392
reducing batch size
shonilbhide Apr 7, 2025
9fbf6e6
fixing command line length issues
shonilbhide Apr 7, 2025
6072066
fixing typos
shonilbhide Apr 7, 2025
b0e832c
change to extract test identifiers from the function wrapper format t…
shonilbhide Apr 7, 2025
b286ec1
reverting changes
shonilbhide Apr 7, 2025
442bea1
reverting changes
shonilbhide Apr 7, 2025
54bb33f
Fix test identifier processing and add workflow ID support to prevent…
shonilbhide Apr 8, 2025
9d07d49
Fix naming
ShubhamDesai Apr 13, 2025
cdf272c
adding dev branch
ShubhamDesai Apr 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 96 additions & 31 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- dev
- "[0-9]+.[0-9]+.x"
- "test-me-*"
tags:
Expand All @@ -13,13 +14,14 @@ on:
pull_request:
branches:
- main
- dev
- "[0-9]+.[0-9]+.x"
types: [opened, synchronize, reopened, ready_for_review]

env:
PYTEST_ADDOPTS: "--color=yes"
SETUPTOOLS_SCM_PRETEND_VERSION: "7.3.1.dev0"
SETUPTOOLS_SCM_NO_LOCAL_VERSION: "1"
# SETUPTOOLS_SCM_PRETEND_VERSION: "7.3.1.dev0"
# SETUPTOOLS_SCM_NO_LOCAL_VERSION: "1"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -95,15 +97,18 @@ jobs:
python-version: ${{ matrix.python }}

- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
pip install tox pytest-json-report jq

- name: Get PR ID
shell: bash
if: github.event_name == 'pull_request'
run: echo "PR_ID=${{ github.event.number }}" >> $GITHUB_ENV

- name: Set Default Folder for Non-PR Runs
shell: bash
if: github.event_name != 'pull_request'
run: echo "PR_ID=main" >> $GITHUB_ENV

Expand Down Expand Up @@ -162,8 +167,9 @@ jobs:
REMAINING_TESTS_FILE="artifacts/pr-${PR_ID}/remaining_tests.txt"

# Use tox to collect all tests
tox -e ${{ matrix.tox_env }} -- --collect-only --quiet | grep "::" > $ALL_TESTS_FILE || true

tox -e ${{ matrix.tox_env }} -- --collect-only --quiet | grep -v "SKIP" | grep "::" > $ALL_TESTS_FILE || true
#tox -e ${{ matrix.tox_env }} -- --collect-only -v | grep -v "SKIP" | grep -E "^(.*?)::" | sed -E 's/\s+.*$//' > $ALL_TESTS_FILE || true

if [[ -f "$PREV_RESULTS" ]]; then
echo "Extracting failed test cases from previous run..."
cat $PREV_RESULTS | jq -r '.tests | map(select(.outcome == "failed")) | .[].nodeid' > $FAILED_TESTS_FILE
Expand All @@ -178,31 +184,77 @@ jobs:
else
echo "No previously failed tests found."
fi


- name: Pre-Check for Previously Failed Tests
shell: bash
run: |
FAILED_TESTS_FILE="artifacts/pr-${PR_ID}/failed_tests.txt"
SKIPPED_TESTS_FILE="artifacts/pr-${PR_ID}/skipped_tests.txt"

# Only run this check if we have previously failed tests
if [[ -s "$FAILED_TESTS_FILE" ]]; then
echo "Checking for skipped tests among previously failed tests..."
tox -e ${{ matrix.tox_env }} -- --collect-only -v $(cat $FAILED_TESTS_FILE) | grep "SKIP" | grep "::" | sed 's/.*SKIP //g' > $SKIPPED_TESTS_FILE

# Remove skipped tests from the failed tests list
if [[ -s "$SKIPPED_TESTS_FILE" ]]; then
echo "Removing skipped tests from the rerun list:"
cat $SKIPPED_TESTS_FILE
grep -v -F -f $SKIPPED_TESTS_FILE $FAILED_TESTS_FILE > "artifacts/pr-${PR_ID}/filtered_failed_tests.txt"
mv "artifacts/pr-${PR_ID}/filtered_failed_tests.txt" $FAILED_TESTS_FILE
else
echo "No skipped tests found among previously failed tests."
fi
fi

- name: Generate Failed Test Commands
shell: bash
run: |
FAILED_TESTS_FILE="artifacts/pr-${PR_ID}/failed_tests.txt"

if [[ -s "$FAILED_TESTS_FILE" ]]; then
python scripts/generate_pytest_commands.py --input artifacts/pr-${PR_ID}/remaining_tests.txt --output-dir artifacts --pr-id ${PR_ID} --generate-script --batch-size 50 --tox-env ${{ matrix.tox_env }}
fi

- name: Run Previously Failed Tests First
shell: bash
run: |
FAILED_TESTS_FILE="artifacts/pr-${PR_ID}/failed_tests.txt"

if [[ -s "$FAILED_TESTS_FILE" ]]; then
echo "Rerunning previously failed tests using tox env ${{ matrix.tox_env }}..."
tox -e ${{ matrix.tox_env }} -- --tb=short --json-report --json-report-file=artifacts/pr-${PR_ID}/temp_test_results.json $(cat $FAILED_TESTS_FILE) || true

if [[ -f "artifacts/pr-${PR_ID}/run_failed_tests.sh" ]]; then
chmod +x artifacts/pr-${PR_ID}/run_failed_tests.sh
bash artifacts/pr-${PR_ID}/run_failed_tests.sh
else
echo "No failed test script generated."
fi
else
echo "No previously failed tests found."
fi


- name: Check If Any Tests Failed Again
shell: bash
run: |
TEMP_RESULTS="artifacts/pr-${PR_ID}/temp_test_results.json"
FAILED_AGAIN_FILE="artifacts/pr-${PR_ID}/failed_again.txt"

if [[ -f "$TEMP_RESULTS" ]]; then
echo "Checking if any tests failed again..."
echo "Analyzing test results..."
# Extract failed tests (excluding skipped)
cat $TEMP_RESULTS | jq -r '.tests | map(select(.outcome == "failed")) | .[].nodeid' > $FAILED_AGAIN_FILE
# Extract skipped tests for reporting
cat $TEMP_RESULTS | jq -r '.tests | map(select(.outcome == "skipped")) | .[].nodeid' > "artifacts/pr-${PR_ID}/skipped_tests_report.txt"

# Report on skipped tests
if [[ -s "artifacts/pr-${PR_ID}/skipped_tests_report.txt" ]]; then
echo "The following tests were skipped during execution:"
cat "artifacts/pr-${PR_ID}/skipped_tests_report.txt"
fi
fi

if [[ -s "$FAILED_AGAIN_FILE" ]]; then
echo "Some tests failed again. Stopping execution."
exit 1
Expand All @@ -225,39 +277,52 @@ jobs:
echo "No remaining tests to run."
fi

- name: Set Workflow ID
shell: bash
run: echo "WORKFLOW_ID=${{ matrix.name }}" >> $GITHUB_ENV

- name: Generate Test Commands
shell: bash
run: |
python scripts/generate_pytest_commands.py --input artifacts/pr-${PR_ID}/remaining_tests.txt --output-dir artifacts --pr-id ${PR_ID} --workflow-id ${WORKFLOW_ID} --generate-script --batch-size 20 --tox-env ${{ matrix.tox_env }}

- name: Display Retrieved Test Results
shell: bash
run: |
RUN_TESTS_FILE="artifacts/pr-${PR_ID}/run_tests.sh"
if [[ -f "$RUN_TESTS_FILE" ]]; then
echo "Content of run_tests.sh:"
cat "$RUN_TESTS_FILE"
else
echo "run_tests.sh file does not exist."
fi

- name: Run Remaining Test Cases
shell: bash
run: |
REMAINING_TESTS_FILE="artifacts/pr-${PR_ID}/remaining_tests.txt"

if [[ -s "$REMAINING_TESTS_FILE" ]]; then
echo "Running remaining test cases using tox env ${{ matrix.tox_env }}..."

# 1. Split the test list into chunks of 300 lines each (adjust as needed).
CHUNK_SIZE=300
split -l $CHUNK_SIZE $REMAINING_TESTS_FILE chunk_

i=1
for chunk in chunk_*; do
echo "Running chunk #$i with $(wc -l < "$chunk") tests"

# 2. Pass those tests as arguments to tox in smaller batches
tox -e ${{ matrix.tox_env }} -- --tb=short --json-report \
--json-report-file=artifacts/pr-${PR_ID}/test_results.json \
$(cat "$chunk") || true

((i++))
done

if [[ -f "artifacts/pr-${PR_ID}/run_tests.sh" ]]; then
chmod +x artifacts/pr-${PR_ID}/run_tests.sh
bash artifacts/pr-${PR_ID}/run_tests.sh
else
echo "No test script generated."
fi
else
echo "No remaining tests to run."
fi


- name: Upload New Test Results
uses: actions/upload-artifact@v4
with:
name: pr-${{ env.PR_ID }}-test-results
path: artifacts/pr-${{ env.PR_ID }}/test_results.json
name: pr-${{ env.PR_ID }}-${{ env.WORKFLOW_ID }}-test-results
path: |
artifacts/pr-${{ env.PR_ID }}/${{ env.WORKFLOW_ID }}/*.json
artifacts/pr-${{ env.PR_ID }}/${{ env.WORKFLOW_ID }}/*.sh



retrieve-results:
Expand All @@ -275,7 +340,7 @@ jobs:
- name: Download Test Results
uses: actions/download-artifact@v4
with:
name: pr-${{ env.PR_ID }}-test-results
name: pr-${{ env.PR_ID }}-${{ env.WORKFLOW_ID }}-test-results
path: retrieved-results

- name: Display Retrieved Test Results
Expand Down
Loading
Loading