Skip to content

armgit / rembg

Public Imported from GitHub
0

Rembg is a tool to remove images background

add tests summary

Daniel Gatise9e12a1caab6
diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml
index 4a87356..118fca1 100644
--- a/.github/workflows/test_install.yml
+++ b/.github/workflows/test_install.yml
@@ -29,3 +29,39 @@ jobs:
exit 1
fi
pytest
+
+ - name: Show test failures in summary
+ if: always()
+ run: |
+ echo "## 🧪 Test Results - Python ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
+ echo "" >> $GITHUB_STEP_SUMMARY
+
+ if [ -d "tests/failures" ] && [ "$(ls -A tests/failures)" ]; then
+ echo "### ❌ Falhas Detectadas" >> $GITHUB_STEP_SUMMARY
+ echo "" >> $GITHUB_STEP_SUMMARY
+
+ # Processa pares de imagens (actual e expected)
+ for actual_img in tests/failures/*.actual.png; do
+ if [ -f "$actual_img" ]; then
+ # Extrai o nome base (ex: anime-girl-1.u2net)
+ base_name=$(basename "$actual_img" .actual.png)
+ expected_img="tests/failures/${base_name}.expected.png"
+
+ if [ -f "$expected_img" ]; then
+ echo "<details>" >> $GITHUB_STEP_SUMMARY
+ echo "<summary>🔴 $base_name</summary>" >> $GITHUB_STEP_SUMMARY
+ echo "" >> $GITHUB_STEP_SUMMARY
+ echo "| Esperado (Expected) | Atual (Actual) |" >> $GITHUB_STEP_SUMMARY
+ echo "|---------------------|----------------|" >> $GITHUB_STEP_SUMMARY
+ echo "| ![Expected](data:image/png;base64,$(base64 < "$expected_img")) | ![Actual](data:image/png;base64,$(base64 < "$actual_img")) |" >> $GITHUB_STEP_SUMMARY
+ echo "" >> $GITHUB_STEP_SUMMARY
+ echo "</details>" >> $GITHUB_STEP_SUMMARY
+ echo "" >> $GITHUB_STEP_SUMMARY
+ fi
+ fi
+ done
+ else
+ echo "### ✅ Todos os testes passaram!" >> $GITHUB_STEP_SUMMARY
+ echo "" >> $GITHUB_STEP_SUMMARY
+ echo "Nenhuma diferença detectada nas imagens geradas." >> $GITHUB_STEP_SUMMARY
+ fi
diff --git a/tests/test_remove.py b/tests/test_remove.py
index 6e7ee75..3853077 100644
--- a/tests/test_remove.py
+++ b/tests/test_remove.py
@@ -7,6 +7,8 @@ from PIL import Image
from rembg import new_session, remove
here = Path(__file__).parent.resolve()
+failures_dir = here / "failures"
+failures_dir.mkdir(exist_ok=True)
def test_remove():
kwargs = {
@@ -69,4 +71,16 @@ def test_remove():
print(f"actual_hash == expected_hash: {actual_hash == expected_hash}")
print("---\n")
+ if actual_hash != expected_hash:
+ # Salva as imagens que falharam para comparação
+ actual_failure_path = failures_dir / f"{picture}.{model}.actual.png"
+ expected_failure_path = failures_dir / f"{picture}.{model}.expected.png"
+
+ with open(actual_failure_path, "wb") as f:
+ f.write(actual)
+ with open(expected_failure_path, "wb") as f:
+ f.write(expected)
+
+ print(f"FAILURE: Saved comparison images to {failures_dir}")
+
assert actual_hash == expected_hash