Copilot 채팅는 테스트 실패를 분석하고 잠재적인 원인을 식별하는 데 도움이 될 수 있습니다.
예제 시나리오: 로컬에서 통과하지만 CI에서 실패하는 테스트
로컬 머신을 통과하지만 CI에서 실패하는 테스트가 있는 시나리오를 고려해 보세요. Copilot 채팅는 실패 원인을 식별하는 데 도움이 될 수 있습니다.
이 예제에서 테스트 중인 코드는 단순 주문 서비스(order.py)를 정의하며, 현재 주문test_order_service.py이 만들어졌는지()를 확인하는 해당 테스트가 있습니다.
예시 프롬프트
아래 프롬프트는 Copilot에 관련 코드와 테스트 파일(#file: 사용)을 제공하며, CI 실패와 관련된 발췌 부분을 복사하여 붙여넣기 형태로 포함합니다.
Please take a look at this CI failure message. The test passes locally, but intermittently fails in CI. Can you help me figure out if this looks like a code bug, environment issue, or a flaky test? Failure: ___ TestOrderService.test_order_created_today ___ > assert order["created_date"] == date.today() E AssertionError: assert datetime.date(2024, 1, 15) == datetime.date(2024, 1, 16) test_order_service.py:45: AssertionError #file:order.py #file:test_order_service.py
Please take a look at this CI failure message. The test passes locally, but intermittently fails in CI. Can you help me figure out if this looks like a code bug, environment issue, or a flaky test?
Failure:
___ TestOrderService.test_order_created_today ___
> assert order["created_date"] == date.today()
E AssertionError: assert datetime.date(2024, 1, 15) == datetime.date(2024, 1, 16)
test_order_service.py:45: AssertionError
#file:order.py
#file:test_order_service.py
응답 예제
참고
다음 응답이 예제입니다. Copilot 채팅 응답은 비결정적이므로 여기에 표시된 응답과 다른 응답을 얻을 수 있습니다.
Copilot 채팅은 날짜가 정확히 하루 떨어져 있음을 확인하고 이것이 표준 시간대 또는 시간 경계 문제일 수 있음을 식별합니다.
로컬 컴퓨터와 CI 실행기는 서로 다른 표준 시간대 설정을 사용하거나 다른 시계(UTC와 현지 시간)에서 파생today될 수 있으므로, 자정에 가까운 시간에 테스트가 실행될 때 각 환경에서 반환되는 날짜가 서로 다를 수 있습니다.
Copilot 채팅은(는) 이 실패를 논리 버그가 아닌 환경/시간 가정으로 인한 테스트 불안정성으로 보고, 환경 간 today가 계산되는 방법을 표준화하여 이를 수정할 것을 제안합니다.
예제 시나리오 2: 일시적인 테스트 실패
동일한 컴퓨터에서 테스트가 통과되고 때로는 실패하는 시나리오를 고려해 보세요. Copilot 채팅을(를) 통해 성공한 실행과 실패한 실행의 로그를 비교함으로써 문제의 원인을 파악할 수 있습니다.
이 예제에서 테스트 중인 코드는 백그라운드 작업을 order_service.py 사용하여 주문의 상태를 비동기적으로 업데이트하고, test_order_service.py 테스트에서 최종 상태가 "processed" 인지 확인합니다.
예시 프롬프트
아래 프롬프트에는 Copilot에서 발생한 오류 메시지, 성공 및 실패 실행에서 추출한 로그, 그리고 관련 코드 파일(#file: 사용)이 포함되어 있습니다.
This test passes sometimes and fails sometimes. Can you compare the logs and help me figure out why? Failure message: > assert order.status == "processed" E AssertionError: assert "pending" == "processed" test_order_service.py:62: AssertionError Logs from a passing run: [DEBUG] Created order #1234 [DEBUG] Background job started for order #1234 [DEBUG] Background job completed (52ms) [DEBUG] Checking order status [DEBUG] Order #1234 status: processed Logs from the failing run: [DEBUG] Created order #1234 [DEBUG] Background job started for order #1234 [DEBUG] Checking order status [DEBUG] Order #1234 status: pending #file:order_service.py #file:test_order_service.py
This test passes sometimes and fails sometimes. Can you compare the logs and help me figure out why?
Failure message:
> assert order.status == "processed"
E AssertionError: assert "pending" == "processed"
test_order_service.py:62: AssertionError
Logs from a passing run:
[DEBUG] Created order #1234
[DEBUG] Background job started for order #1234
[DEBUG] Background job completed (52ms)
[DEBUG] Checking order status
[DEBUG] Order #1234 status: processed
Logs from the failing run:
[DEBUG] Created order #1234
[DEBUG] Background job started for order #1234
[DEBUG] Checking order status
[DEBUG] Order #1234 status: pending
#file:order_service.py
#file:test_order_service.py
응답 예제
참고
다음 응답이 예제입니다. Copilot 채팅 응답은 비결정적이므로 여기에 표시된 응답과 다른 응답을 얻을 수 있습니다.
Copilot 채팅은(는) 두 로그를 비교하고 통과 실행 시 백그라운드 작업이 상태 확인 전에 완료된 반면 실패한 실행에서는 작업이 실행되는 동안 상태를 확인했음을 알 수 있습니다. 백그라운드 작업의 완료를 기다리지 않는 Copilot 채팅 테스트로 인해 경합 상태가 발생함을 주목합니다.
Copilot 채팅는 작업이 완료된 후에 검증을 수행하도록 하기 위해 동기적으로 작업을 실행하거나, 완료를 대기하거나(예: 콜백을 통해), 또는 폴링하는 등의 메커니즘을 추가할 것을 제안합니다.
추가 읽기
데이터 재사용 가능.코파일럿.예제-프롬프트.추가-읽기-항목 %}