MulaiMulai sekarang secara gratis

Failed tests with xfail

In this exercise, you will use pytest markers for the first time in order to specify the behavior of the test. You have already seen the function multiple_of_two, which checks whether the num is a multiple of 2 or not. The pytest library was already imported for you.

Latihan ini adalah bagian dari kursus

Introduction to Testing in Python

Lihat Kursus

Petunjuk latihan

  • Add the correct pytest marker for a test that is expected to fail.
  • Write any assert test that is expected to fail.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

def multiple_of_two(num):
    if num == 0:
        raise(ValueError)
    return num % 2 == 0

# Add the pytest marker decorator here
____.____.____
def test_fails():
    # Write any assert test that will fail
    ____ multiple_of_two(____) ____ ____
Edit dan Jalankan Kode