Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

tip for rerunning failed tests #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions src/content/tips/rerun-failed-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
kind: circleci
title: Rerun only the failed tests when you hit flaky test failures
description: Save time and money by avoiding rerunning tests that already passed when you hit flaky test failures
contributor: https://github.com/sebastian-lerner
snippet: |
version: 2.1
jobs:
test:
docker:
- image: cimg/python:3.11.0
parallelism: 4
steps:
- checkout
- python/install-packages:
pkg-manager: pip
- run:
command: |
mkdir test-results
TEST_FILES=$(circleci tests glob "**/test_*.py")
echo "$TEST_FILES" | circleci tests run --command="xargs pytest -o junit_family=legacy --junitxml=test-results/junit.xml" --verbose --split-by=timings #--split-by=timings optional
- store_test_results:
path: test-results
---

If your test suite is prone to flaky test failures, you are probably wasting time and money re-running the entire test suite just to get to a passing build. CircleCI lets you cut down on that wasted time/money by only re-running the tessts that failed when you hit flaky test failures. No need to rerun the tests that passed.

The snippet above shows an example using Python & `pytest`, but you can use this functionality with almost any framaework/test runner. See the [official CircleCI documentation on rerunning only the failed tests](https://circleci.com/docs/use-the-circleci-cli-to-split-tests/](https://circleci.com/docs/rerun-failed-tests/)https://circleci.com/docs/rerun-failed-tests/) for more details.