Predicting pytest outcomes for a buggy leap-year function

A developer implements a leap-year check but forgets the century rule (years divisible by 100 are leap years only when also divisible by 400):


Python
# calendar_utils.py
def is_leap(year):
    return year % 4 == 0


The test module is:


Python
# test_calendar.py
import pytest
from calendar_utils import is_leap

@pytest.mark.parametrize("year", [2024, 2000])
def test_leap(year):
    assert is_leap(year)

@pytest.mark.parametrize("year", [2023, 1900])
def test_not_leap(year):
    assert not is_leap(year)

def test_rejects_text():
    assert is_leap("2024") is False


In the table, each row names a test case by its test and year; the row rejects text is test_rejects_text. Fill in each case's pytest outcome using one of the words passed, failed, error or skipped, then give the number of failed cases and the exit code pytest returns.

Test caseOutcome
leap 2024
leap 2000
not leap 2023
not leap 1900
rejects text
Number of failed cases
pytest exit code

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Doctest Questions: